11

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

2 Answers 2

17
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

Sign up to request clarification or add additional context in comments.

Comments

6

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.