views:

1225

answers:

3

I have a text file that contains a list of filenames, minus the extension, that I need to create. I want to run a quick batch file command or VBS script that will iterate through the list and then create a file based on the name.

The text file looks something like this:

PRXI0000466
PRXI0000564
PRXI0000636
PRXI0000681
PRXI0001092

So I want to loop through each line, then do an "echo . > %file%.txt" (assuming %file% contains the line from the text file).

Can anyone show me a quick way to do this?

+1  A: 

Are you just trying to create empty text files? If so, this .vbs script will do it

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list.txt")
do while not listFile.AtEndOfStream 
    fName =  listFile.ReadLine()
    fso.CreateTextFile(fName + ".txt")
loop
Gareth Simpson
+5  A: 

Well, this is a one-liner in cmd:

for /f %i in (textfile.txt) do @echo . > %i.txt

for /f loops line-wise hrough a text file, and doing tokenizing on the way as well. Luckily for you there are no spaces in your lines, otherwise this would have called for something like "delims=" on there as well.

This would put a single line containing a dot follows by a space in each new file. If you just want a blank line you'd have to use echo.>%i.txt. If you just want to create each file (UNIX geeks might just use touch(1)) you can use copy NUL %i.txt. If you want to use this in a batch file (and not directly from the command line) then you'd have to use %%i instead of %i.

I think you really want to create empty files, so the following should do the trick:

for /f %i in (textfile.txt) do @copy nul %i.txt
Joey
A: 

The text file t.txt contains:

PRXI0000466
PRXI0000564
PRXI0000636
PRXI0000681
PRXI0001092

This loop should solve your problem.

for /f %%a in (t.txt) do %%a > %%a.txt
Secko