Create, Copy, Replace, Delete Files and Folders with CMD


This is How To Create, Copy, Replace, Delete Files and Folders via command line:

1. specify the destination directory:
2. creating a folder in cmd:
mkdir foldername
3. deleting a folder in cmd:

Type the following command to delete folder and subfolders with contents:


Type the following command to delete a folder with content:


delete a folder with content recursively without confirmation prompt:

4. copying a folder in cmd:
Xcopy C:\test D:\test /E /H /C /I

/E – Copy sub directories, including any empty ones.
/H – Copy files with hidden and system file attributes.
/C – Continue copying even if an error occurs.
/I – If in doubt, always assume the destination is a folder. e.g. when the destination does not exist.

Xcopy will not copy open files.
Xcopy doesn’t display any progress or completed operations information when executed.

Remember that for folders with spaces in the name or folders larger than 8 characters in length, it is a good idea to put quotation marks around the path as in the figure above or you may get an error.

5. creating a file in cmd:

if you want to create an empty file use:

type nul > filename.txt

if you want to create a file with content with it use:

echo yourcontenthere > filename.txt
6. deleting a file in cmd:
del filename.txt

If you get an error that says the file cannot be deleted, try using del /f filename instead, as this force-deletes read-only files.
If the file’s name has a space in it (e.g., “hi there”), you will place the file’s name in quotations (e.g., del “hi there”).

7. copying a file in cmd:
copy c:\filename.txt d:\destination
8. replacing copying a file in cmd:
replace "%CD%\filename.txt" "%USERPROFILE%\FOLDER"

you can use %CD% as current path.
you can use %USERPROFILE% as user profile path.

Sharing is caring!


DZ4Team is a Web development team, We offer all types of scripts, installing, supporting and hosting. Contact Us:

Leave a Reply