Andrew  Nexintong
Andrew Nexintong

Reputation: 1051

How to create txt files named as file listed by the command 'dir'?

I need to create a txt file with the same name (excluded the extension) for each file present into a directory. For instance in a directory I have a file named setup.exe, I'd like to add an empty txt file into the same directory named setup.txt.

Is this able and if yes, how?

Upvotes: 0

Views: 242

Answers (1)

dhilmathy
dhilmathy

Reputation: 2868

Try this from cmd

FOR /R "C:\your_folder" %f IN (*.*) DO (TYPE NUL > %~pf%~nf.txt) 

If you're inside the working directory, you can skip the path

FOR /R %f IN (*.*) DO (TYPE NUL > %~pf%~nf.txt) 

If you're planning to run from bat file, use two %%

FOR /R "C:\your_folder" %%f IN (*.*) DO (TYPE NUL > %%~pf%%~nf.txt) 

To exclude existing txt files,

FOR /R %f IN (*.*) DO (IF %~xf NEQ .txt (TYPE NUL > %~pf%~nf.txt))

Upvotes: 1

Related Questions