Question:
From this answer I can create multiple files a.txt, b.txt, … , z.txt. in Bash with:
1 2 |
touch {a..z}.txt |
Or 152 with:
1 2 |
touch {{a..z},{A..Z},{0..99}}.txt |
How can I do this in Powershell?
I know New-Item a.txt
, but If I want multiple files as above?
For curiosity, what are the equivalent commands in Command Prompt (cmd.exe)?
Answer:
For Powershell:
1 2 |
1..5 | foreach { new-item -path c:\temp\$_.txt } |
The foreach
loop will run for each number in 1 to 5, and generate a file in the desired path with the name of that number passed to the command (represented by the $_
)
You could also write it as:
1 2 |
%{1..5} | new-item c:\temp\$_.txt |
For cmd:
1 2 |
for /L %v in (1,1,5) do type nul > %v.txt |
More information here: cmd/batch looping