2

I am trying to create multiple empty files to my project from the command prompt(Windows) and I always used the touch command. but what can I use if I want to create more files in the same line.

Thanks a lot!

Roee Angel
  • 123
  • 12
  • 4
    Does this answer your question? [How to create an empty file at the command line in Windows?](https://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line-in-windows) – dan1st Mar 13 '20 at 21:25
  • @dan1st - The answer indicated as duplicate only addresses how to create one (1) empty file. The OP wants to create many. – lit Mar 14 '20 at 07:28

3 Answers3

3

You can use the FOR command like this:

FOR %N IN (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) DO (echo null > C:\temp\%N.txt)

This will create 26 empty .txt files with one line.

If you want to clean up the files created, use this:

FOR %N IN (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) DO (del C:\temp\%N.txt)

sippybear
  • 256
  • 2
  • 6
3

A FOR loop will allow you to make as many files as you want. The following command creates ten (10) files.

FOR /L %A IN (1,1,10) DO (TYPE>"%TEMP%\%~A.txt" NUL)

If this is used in a .bat file script, be sure to double the % character on the variable.

FOR /L %%A IN (1,1,10) DO (TYPE>"%TEMP%\%%~A.txt" NUL)
lit
  • 13,209
  • 9
  • 55
  • 92
  • I get error when running this script on Windows 10 in BAT file: "%%A was unexpected at this time." – Boris Zinchenko Nov 07 '21 at 11:53
  • 1
    @BorisZinchenko, sorry, there needs to be a SPACE character between `IN` and `(`. Also, the first line is for use at the interacting cmd.exe prompt. The second line is for use in a .bat file script. – lit Nov 07 '21 at 13:47
  • Thank you so much! Everybody trying to copy this line from here, be aware that you must explicitly put spaces instead of other characters copied by browser. I was totally confused. It was very hard to distinguish. Now it works perfectly. – Boris Zinchenko Nov 07 '21 at 16:18
  • @רועי אנגל, if you have a answer, please select what you consider to be the best answer and select the check mark for that answer. That is how SO works. – lit Nov 07 '21 at 18:06
2

Great solutions for a huge number of files although
they just didn't work for me. Here is what
worked for me using windows CMD or VScode Terminal/

Create multiple files:

ni file_name.php, other.css, thirdexample.html

Create multiple directories:

mkdir folder-a, folderama, library
Dharman
  • 26,923
  • 21
  • 73
  • 125
Sagive
  • 1,526
  • 1
  • 20
  • 31