我是一名学生,在堆栈溢出时出现在这里。 我目前正在为我的操作系统类创建一个项目。其中一个菜单是:用户可以创建,重命名和删除目录中任何位置的某个文件。我已经知道如何重命名和删除一个文件,但我很难找到正确的命令来创建一个文件,其中用户可以确定某个文件将是什么文件扩展名。批处理文件 - 使用文件扩展名创建文件
这是有点像这样:
//这是展示什么可用的驱动器的计算机有
echo Here are the available drives:
echo.
wmic logicaldisk get name
echo.
echo.
set /p ch2=Which drive do you want to access?
for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do @echo %%x >>drive%%x.txt
if exist D:\drive!ch2! (
goto specificview
)
else (
goto Invalid
)
//这里的用户所选择的驱动器将其保存的文件进行查看和用户被要求下一步做什么
:specificview
cls
set ch3=
dir !ch2!:\ /w /a
pause
echo.
echo.
echo What do you want to do in this directory?
echo ================================================================
echo Press [X] to go back to choose directory
echo Press [w] to Exit
echo Press [C] to create File
echo If none of the choices, type down the name of the directory file
echo NOTE: Just press [1] to go back to the main MENU
echo ================================================================
//假设用户会选择C创建文件
set /p ch3= Please Choose:
if /i !ch3!==c (
set /p crt=Input the name of the filename:
set /p ext=Input the desired extension:
现在,我不知道我应该使用什么命令才能完成代码。我想问你的帮助,以便我可以完成我的项目。
非常感谢。
也许'%crt%。%ext%'帮助从这里讨论http://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line- in-windows –
Roelant
感谢您的反馈。我已经创建了这个批处理文件的重命名和删除部分,但是我没有将它包含在这篇文章中。如果我们可以只指定文件扩展名如.txt,但我们的任务是根据用户的需求进行设置,那将会很容易。 – Kurazo
我现在要试一下这段代码。再次感谢您的帮助。 – Kurazo