Introduction
Batch files give you simple but powerful ways to create, delete, rename, and move files. This tutorial shows the most important file operations you will use in real Batch projects.
Creating a File
You use the echo command to write text into a file.
echo Hello World! > example.txt
Note: If the file exists, it will be overwritten.
Appending to a File
echo This line is added later >> example.txt
>> means “append” instead of overwriting.
Reading a File Line by Line
Use a for /f loop to read text files:
for /f "tokens=*" %%A in (example.txt) do (
echo Line: %%A
)
Deleting a File
del /f /q example.txt
- /f = force delete
- /q = quiet mode (no confirmation)
Renaming Files
ren oldname.txt newname.txt
Moving Files
move notes.txt C:\Users\Public\
Copying Files
copy source.txt backup.txt
Checking If a File Exists
if exist data.txt (
echo File found!
) else (
echo File missing!
)
Creating a Folder
mkdir MyFolder
Deleting a Folder
rmdir /s /q MyFolder
/s = delete contents • /q = quiet mode
What's Next?
Now you know the core file commands used in Batch automation, cleanup scripts, installers, and tools. Next, you can explore Batch loops, arguments, and more advanced automation.