Roee Angel
Roee Angel

Reputation: 201

How to create multiple empty files using command prompt in Windows

I am working on a project where I need to create multiple empty files. In the past, I have used the touch command, but this only allows me to create one file at a time. Is there a way to create multiple empty files using the command prompt in Windows?

I appreciate any suggestions or solutions you may have. Thank you!

Upvotes: 3

Views: 4665

Answers (3)

lit
lit

Reputation: 16266

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)

Upvotes: 5

Sagive
Sagive

Reputation: 1837

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

Upvotes: 2

sippybear
sippybear

Reputation: 276

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)

Upvotes: 3

Related Questions