In this tutorial we will discuss about the commands to copy and remove the files and Directories in Windows with different options and examples.
- COPY
- XCOPY
- ROBOCOPY
- RMDIR
COPY Command:
copy command in windows copies the files from one directory to another directory. It also helps to combine files where multiple files as a source and single file as a destination.
Syntax:
COPY source destination
COPY source1+source2 destination
Copy a file in the Current Folder:
copy abc.txt new_file.txt
Copy from a different folder to directory:
copy C:\Dir1\abc.txt C:\Dir2\new_file.txt
Copy Multiple Files as a Source and Single file as a destination:
copy file1.txt+file2.txt file3.txt
XCOPY Command:
Copies the files and directories into another directory.
Syntax:
XCOPY source destination [options].
They are so many options available. We will see few of them which would be helpful
/S Copy folders and subfolders
xcopy C:\Dir1\Dir2 c:\Dir3 /S
/P Prompt before creating each file.
/C Continue copying if error occurs.
Xcopy Limitation:Insufficient Memory Error
Xcopy fails with an “insufficient memory” error when the path plus filename is longer than 254 characters. The alternative to Xcopy is Robocopy.
ROBOCOPY Command:
Its a Robust File and Folder Copy.
Syntax:
ROBOCOPY source_folder destination_folder [options]
They are so many options available. We will see few of them which would be helpful.
/E: Copy Subfolders, including Empty Folders
Skipped Files:
During the copy of files, some of the files which are empty are Skipped. To overcome this issue use the following Option.
/MIN:n : MINimum file size – exclude files smaller than n bytes.
Example:
ROBOCOPY source_folder destination_folder /E /MIN:0
RMDIR Command
Deletes files and folders.
Syntax:
RD path [options]
/S : Delete all files and subfolders
/Q : Quiet – do not display Y/N confirmation
Example:
Deletes the Folder dir2 and subfolders with-in the dir2 with out prompting the confirmation.
rmdir /S /Q C:\dir1\dir2