Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Windows command shell for creating multiple files

Tags:

shell

windows

cmd

Is there a way of creating multiple files in Windows by using its own command prompt (cmd.exe) or terminal emulator if you call it, just like the below simple one liner would do in any Unix-like system? Note that I'm talking about a situation where I can't use any alternative terminal emulators like PowerShell or Win 32 ports of GNU utils.

for i in `seq 10` ; do `touch $i.txt`; done
like image 344
oakenshield1 Avatar asked Mar 10 '15 14:03

oakenshield1


People also ask

How do I create multiple files in Windows?

Nothing is probably easier than creating new files and folders in Windows. Just right-click in the blank space, select New and choose whatever you want to create: a File, a Folder, or even a shortcut.

How do I make multiple files at once?

Instead, you can create multiple folders at once using the Command Prompt, PowerShell, or a batch file. These apps save you from the task of right-clicking > New Folder or using Ctrl+Shift+N to make a new folder, which is tiresome if you have to make several of them.

How to create a new file in command prompt?

Open the Command Prompt window. Use the cd command to go to the folder where you want to create the file. Use the below command to create a new file in Command Prompt. You can replace the dummy content with the content of your choice and the file extension can be anything.

How to create a new file with PowerShell command-line tool?

You can use the New-Item cmdlet to create a new file with the PowerShell command-line tool. Here’s how. 1. Open the PowerShell window. 2. Use the cd command to go to the directory where you want to create the new file. 3. Execute the below command to create a new file. Replace “filename.txt” with the file name and type of your choice.

How to create a new file from a folder in Linux?

1. Open the Command Prompt window. 2. Use the cd command to go to the folder where you want to create a new file. 3. Execute the below command to create a new blank file. The file can be of any extension. 4. To create a new file with specific file size, use the below command.

How to create multiple folders at once in Windows 10?

Instead, you can create multiple folders at once using the Command Prompt, PowerShell, or a batch file. These apps save you from the task of right-clicking > New Folder or using Ctrl+Shift+N to make a new folder, which is tiresome if you have to make several of them. However, there are ways that you can avoid that.


Video Answer


2 Answers

for /l %a in (1 1 10) do type nul > "%a.txt"

For each value in the sequence from 1 in steps of 1 up to 10, create (> redirection) a empty file (type nul reads nothing and writes nothing) using the value in the sequence as filename (the value in the for replaceable parameter)

The command is written to be used from command line. Inside a batch file percent signs need to be escaped (doubling them), replacing %a with %%a

like image 140
MC ND Avatar answered Oct 26 '22 13:10

MC ND


Use windows syntax:

for %A in (1 2 3) do type nul > file%A.txt

or

for %A in (1 2 3) do echo.> file%A.txt

or

for %A in (1 2 3) do copy nul > file%A.txt
like image 45
Michael Kazarian Avatar answered Oct 26 '22 14:10

Michael Kazarian