Batch file 创建一个文本文件,如果它没有创建,就让它说它是创建的';不能成批存在
因此,我想制作一行简单的代码,使批处理文件创建一个文本文档,同时,它响应“获得成就:开始游戏” (批处理文件已将CD设置为文件夹位置,因此这不是因为我在其中没有完整位置” 使用它时,它确实会创建文件,但批处理文件从不说“获得成就:开始游戏!”而是在运行时创建的文本文件中说 简短版本:如果文件不存在,我希望批处理文件在文件夹中创建一个文本文件,但我也希望它表明文件已创建。Batch file 创建一个文本文件,如果它没有创建,就让它说它是创建的';不能成批存在,batch-file,if-statement,echo,Batch File,If Statement,Echo,因此,我想制作一行简单的代码,使批处理文件创建一个文本文档,同时,它响应“获得成就:开始游戏” (批处理文件已将CD设置为文件夹位置,因此这不是因为我在其中没有完整位置” 使用它时,它确实会创建文件,但批处理文件从不说“获得成就:开始游戏!”而是在运行时创建的文本文件中说 简短版本:如果文件不存在,我希望批处理文件在文件夹中创建一个文本文件,但我也希望它表明文件已创建。 提前感谢。您可以检查文件是否存在: #!/bin/bash file="achievements\Start the Game
提前感谢。您可以检查文件是否存在:
#!/bin/bash
file="achievements\Start the Game.txt"
if [ -f "$file" ]
then
echo "$file found."
else
echo "$file not found."
fi
所以这可以写成
#!/bin/bash
file="/etc/hosts"
if [ -f "$file" ]
then
...do what you will
else
echo "Achievement Get: Start the Game!" > $file
fi
编辑:注意这是Linux
if not exist "achievements\Start the Game.txt" copy nul "achievements\Start the Game.txt">nul&echo Achievement Get: Start the Game!
你没有说你想在文件里放什么。这会使它的长度为零
>nul
会抑制复制的文件
消息
&分隔要级联的命令
它也可以使用
if not exist "achievements\Start the Game.txt" (
copy nul "achievements\Start the Game.txt">nul
echo Achievement Get: Start the Game!
)
我做了一些研究,得出了这个结论
@echo off
if not exist "\achievements\Start the Game.txt" goto a
EXISTS ALREADY
PAUSE
EXIT
:A
cd "\achivements"
echo. 2> "Start the Game.txt"
echo Achievement Get: Start the game !
pause
应该有用
@echo off
if not exist "\achievements\Start the Game.txt" goto a
EXISTS ALREADY
PAUSE
EXIT
:A
cd "\achivements"
echo. 2> "Start the Game.txt"
echo Achievement Get: Start the game !
pause