bat Batch Create/Delete Files/Folders Modify File Names Extensions#
1. Create/Delete Folders#
Command: md foldername
or mkdir foldername
2. Create/Delete Files#
1. Create Empty File#
An empty file means that there is nothing inside the file, it is empty.
Command: type nul>filename
Example: type nul>myvideo.txt
Creates a file named myvideo.txt
2. Create Non-Empty File#
A non-empty file means that there is content inside the file.
Command: echo content>filename
3. Delete File#
Command: del filename
3. Batch Change File Extensions#
Command: ren *.oldextension *.newextension
If you want to change the extension of any file, replace the old extension with an asterisk (*). For example, to change all file extensions to txt, use ren *.* *.txt
4. Rename Files with a Regular Pattern and Prefix#
- Create a new text file in the folder where you want to rename the files.
- Enter the following content:
@echo off
set a=0
setlocal EnableDelayedExpansion
for %%n in (*.jpg) do (
set /A a+=1
ren "%%n" "prefix!a!suffix.png"
)
Replace .jpg with the desired file extension to be renamed, and modify the prefix and suffix according to your needs. !a! represents a variable that increases from 0. .png is the new extension after renaming.
3. Save the file and change the extension to .bat
4. Double-click to execute and the renaming will be successful.
This way, all file extensions with .jpg will be changed to .png with a prefix of "prefix-", and the same can be done for other files.
5. Custom Changes to Various Files#
By combining the commands mentioned above with the functionality of Excel, you can quickly generate the files you want. The use of Excel is not explained here.