Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create multiple files using a single command on windows command line?

The command for creating a new file on windows using cmd is:

cd.> filename.txt

But how can I create more than one file using a single command?

like image 654
Rohit Raj Avatar asked Oct 23 '25 20:10

Rohit Raj


1 Answers

With PowerShell you can use New-Item with an array of filenames.

Note: ni is a built-in alias for New-Item, which is useful to substitute interactively.

# New-Item
ni fileA.txt, fileB.txt, filec.txt, "file_with_a_${var}_in_it.txt"

You can also use New-Item to create directories, but a shorter way to do this is to use mkdir instead, which is a built-in "alias" function for essentially calling New-Item -ItemType Directory:

# New-Item -ItemType Directory
mkdir dirA, dirB, dirC

Some tips

  • If you want to suppress the output, you can pipe or redirect the output. Add | Out-Null or
    > $null to either example above (errors and other streams will still show as written).

  • Both commands support fully-qualified paths and relative paths. You can provide a single string if you are only creating one item.

  • You can add as many array elements as you would like, just separate each element in the array with a comma ,. You can also provide an array variable instead if you need.

like image 176
Bender the Greatest Avatar answered Oct 25 '25 10:10

Bender the Greatest



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!