Copying a folder in the command prompt - windows

I am trying to copy a folder from one directory to another in the CMD in Windows 7.
I have found commands for copying individual files:
copy test.txt "C:\NewLocation"
Which works fine. However trying something like this:
copy "C:\Test" "C:\NewLocation"
doesn't work. It wants to take the contents of the directory and move them over. Is there anyway to copy the FOLDER and move it as opposed to the entire directory contents?
Thanks.

Use xcopy instead of copy:
xcopy "C:\Test" "C:\NewLocation" /s /e
source

You can't "copy" folders, but you can "move" them:
move c:\test c:\newlocation

You could use xcopy:
xcopy /S C:\Test C:\NewLocation

Related

How to copy specific files from one folder to another from the command prompt

I have a large folder of pictures (thousands), and I have a long list of files, by exact file name, that I need to copy to another folder using Windows commands, through cmd prompt only. I use Windows 7.
I want to know if there is a way I can select several specific files from this folder, by name, and copy them to another folder, using the terminal, without copying them individually?.
I know I can do it with xcopy but i want to copy specific types of files only say 'jpeg','bmp',etc.
Try using
xcopy /d /y /s "\Your Image Folder\*.jpg" "C:\Users\%username%\Desktop\Master Image Folder\"
Also you can simply use
copy *.<extension> <other folder>
For example :
copy C:\Users\desktop\*.jpg D:\backup
will copy all files with extension .jpg from path C:\Users\desktop\ to D:\backup\
Something like:
xcopy /s "c:\source\*.jpeg" "c:\destination\"
should do the trick. Additionally, if you type xcopy /?, you should get the documentation. (you can replace .jpeg with whatever file extension you want.
The information on the page Microsoft DOS xcopy command provides considerably more information and guidance.
copy c:\scr\*.jpg c:\dst
copy c:\src\*.bmp c:\dst

Windows xcopy 0 File(s) copied

I am trying to copy a directory but get the following:
xcopy ..\node_modules\ \node_modules\
0 File(s) copied
I run as administrator, but still get the error. Any ideas please?
p.s I actually use the following to stipulate it's a directory. But the above also fails:
echo d | xcopy /d /y ..\node_modules\ \node_modules\
Thanks
You can use the xcopy /E flag to copy the entire directory and subdirectories. Also remove the starting \ of the destination. The trailing slash should prevent the file or directory prompt.
xcopy /E ..\node_modules node_modules\
xcopy ..\node_modules\* \node_modules\
You are specifying the source directory, but not which files to copy.
To copy all the contents like folder, sub-folder or chain of folders we can use below command:
xcopy file-to-copy-path\ where-to-copy-path\ /s /i
/s copies folders and sub-folders
/i If in doubt always assume the destination is a folder e.g. when the destination does not exist.

Copy Directory files to another directory in batch file without asking?

I have created a batch file to copy one folders files to another folder.
This code XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q works but when i run this file it ask Overwrite C:\Temp2\a.txt (Yes/No/All)?
I want to do this without asking this question. How can i do ? And i want to this for aspx or aspx.cs files
From the manual:
/Y Suppresses prompting to confirm you want to overwrite an existing
destination file
So just add the /Y option in order to overwrite all files without asking.
If you want to copy all files that contain "aspx", you can use
XCOPY C:\Temp\aspx* C:\Temp2\ /Q /Y
You can try this :
XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q /Y

Batch script to copy folder structure with files skip specific sub-folders

I am trying to copy a folder structure with all data but need to skip folders who have named as 'others'. I created .bat file and trying to move source to destination. I used xcopy /e and exist to check folder but I can't make it. How can I do it?
Use robocopy /E /XD <exclude_file>. See robocopy /? for more options.
create a exclude.txt list into which you can specify which folders or sub folders you want to skip.
use
xcopy "source" "destination" /EXCLUDE:exclude.txt

Windows cmd shell xcopy to network directory doesn't work

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f

Resources