Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create multiple files with Powershell?

Tags:

powershell

cmd

From this answer I can create multiple files a.txt, b.txt, ... , z.txt. in Bash with:

touch {a..z}.txt

Or 152 with:

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)?

like image 779
JDoeDoe Avatar asked Aug 24 '26 01:08

JDoeDoe


1 Answers

For Powershell:

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..5} | new-item c:\temp\$_.txt

For cmd:

for /L %v in (1,1,5) do type nul > %v.txt

More information here: cmd/batch looping

like image 67
sysg0blin Avatar answered Aug 25 '26 15:08

sysg0blin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!