oakenshield1
oakenshield1

Reputation: 871

Using Windows command shell for creating multiple files

Is there a way of creating multiple files in Windows by using its own command prompt (cmd.exe) or terminal emulator if you call it, just like the below simple one liner would do in any Unix-like system? Note that I'm talking about a situation where I can't use any alternative terminal emulators like PowerShell or Win 32 ports of GNU utils.

for i in `seq 10` ; do `touch $i.txt`; done

Upvotes: 11

Views: 22779

Answers (2)

Michael Kazarian
Michael Kazarian

Reputation: 4462

Use windows syntax:

for %A in (1 2 3) do type nul > file%A.txt

or

for %A in (1 2 3) do echo.> file%A.txt

or

for %A in (1 2 3) do copy nul > file%A.txt

Upvotes: 6

MC ND
MC ND

Reputation: 70943

for /l %a in (1 1 10) do type nul > "%a.txt"

For each value in the sequence from 1 in steps of 1 up to 10, create (> redirection) a empty file (type nul reads nothing and writes nothing) using the value in the sequence as filename (the value in the for replaceable parameter)

The command is written to be used from command line. Inside a batch file percent signs need to be escaped (doubling them), replacing %a with %%a

Upvotes: 17

Related Questions