tags:

views:

90

answers:

2

I have a folder of files, e.g: 001zzzqqq.* 002bbbccc.* 003nnnfff.* ...

And want to create a blank text file named after each of those files, e.g: 001zzzqqq.txt 002bbbccc.txt 003nnnfff.txt ...

Any quick way to knock this up in batch file? My mind seems to have gone blank on this.

Thanks

+1  A: 
@echo off
for /f %%a in ('dir /B') do (
  wuauclt > %%~na.txt
)
ghostdog74
`for` can iterate over files just fine, you don't need to drag `dir` and tokenizing into this. Your code breaks with Unicode file names when the console is set to raster fonts as well as with file names that contain spaces (two reasons not to use `for /f` in such cases). Also using a random program to output nothing is ... questionable, at least from the point of someone having to read this.
Joey
+4  A: 

Iterate over the files in the folder:

for %x in (*) do ...

Create empty files:

type NUL > %~nx.txt

The %~nx evaluates to the file name without the extension of the loop variable %x. So, combined:

for %x in (*) do type NUL > %~nx.txt

You could also use copy NUL %~nx.txt but that will output 1 file(s) copied and throw errors if the text file already exists; this is the more silent variant (or use copy /Y NUL %~nx.txt >NUL 2>&1).

In a batch file you need to double the % but you won't need a batch file just for this one-liner (except it's part of a larger program):

for %%x in (*) do type NUL > %%~nx.txt
Joey