1

I am a student and new here in Stack Overflow. I am currently creating a project for my Operating System class. One of the menu would be this: The user can create, rename and delete a certain file anywhere in the directory. I already know how to rename and delete a file but I had a hard time finding the right command to create a file wherein the user can determine what file extension that certain file would be.

It is sort of like this:

//this is to show the user what available drives the computer has

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
)

//here the chosen drive will be viewed with its saved files and the user is asked what to do next

: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 ================================================================

//let's say the user will choose C to create file

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:

Now, I don't know what command I should use in order to complete the code. I would like to ask your help so that I can finish my project.

Thanks a lot in advance.

Kurazo
  • 11
  • 4
  • Maybe `%crt%.%ext%` helps from the discussion here http://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line-in-windows – Roelant Feb 21 '17 at 15:18
  • Thanks for the feedback. I have created the rename and delete section of this batch file but I didn't include it in this post. It would have been easy if we could just specify the file extension such as .txt but we were tasked to make it according to the desire of the user. – Kurazo Feb 21 '17 at 15:20
  • I will now try the code. Thanks again for the help. – Kurazo Feb 21 '17 at 15:29
  • To create an empty file, you could also use [this](http://stackoverflow.com/a/42376467): `rem/ > file.ext` – aschipfl Feb 21 '17 at 19:42

1 Answers1

0

Not really comment, not really answer so I will make it CW!

As this question is not really a duplicate I will add a few things to change it to your needs.

I assume that your file is going to be empty and not using some special formatting or encoding.

As already visible in the answers to above question, there are a lot of ways to do that. I would suggest the answer with the most upvotes that copies NUL to a new file making it empty.
The copy command as you can see is quite simply structured: copy firstFile.something secondFile.somethingElse or in this case copy NUL fileName.ext

So in your case you would go ahead and add the following line:

copy NUL !crt!.!ext!
Community
  • 1
  • 1
geisterfurz007
  • 3,390
  • 5
  • 29
  • 46