Search code examples
powershellshelloperating-systemwindow

How to make multiple files using Powershell


How to change this command to make file name 001.js , 002.js , 003.js ... instead of 1.js , 2.js , 3.js ... ?

1..100 | foreach {New-Item -path "C:\Users\suuii\Desktop\A\$_.js"

Solution

  • One alternative:

    1..100 | % { "{0:d3}" -f $_ } | % { ni "C:\Users\suuii\Desktop\A$_.js" }
    

    Another:

    1..100 | % tostring 000 | % { ni "C:\Users\suuii\Desktop\A$_.js" }