Windows cmd shell xcopy to network directory doesn't work - windows

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

Related

Batch program to copy file when there is a change in source folder

I need a batch program that will copy files from source folder to destination folder whenever there is a change(new files added or files modified) in source folder and restart a specific service.
Refer to the help of xcopy /? using the switch /D
/D : Copy files changed on or after the specified date.
If no date is given, copy only files whose
source date/time is newer than the destination time.
Syntax :
XCOPY source [destination] [options]
Remark :
So, in this batch file below, if you have any spaces in your directory names, you need to enclose them in double quotes.
#echo off
Set SourceDir="C\My Source\stuff"
Set TargetDir="D:\My Backup\stuff"
xcopy %SourceDir% %TargetDir% /i /d /y /e
/D : copy only files whose source date/time is newer than the destination time.
/E : To copy everything, including new directories, you should add the /e switch
/Y : Suppress prompt to confirm overwriting a file.
/I : If in doubt always assume the destination is a folder e.g. when the destination does not exist.

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.

Delete files do not exist in source folder in cmd?

I have two folders that I backup from source to destination folder using command:
xcopy /E /Y /I /D
Now I want to delete files in destination folder that do not exist in source folder.
There is no 'mirroring' option in xcopy. I have 2 suggestions:
1.
you could run xcopy dest source /L > todelete.txt to obtain a list of files which exist in dest but not in source. Then use a for loop to delete these files in dest.
or
2.
Use robocopy which was designed to use the same options as xcopy but has a lot more funtionality. For instance, a /MIR option to mirror one folder to the other. robocopy is included in all Windows versions from Vista on (the Win7 version might run under XP as well - not tested though).
Besides, it is way faster and and and...

Remove Directory Command is not working as expected

I have following batch script. It takes data from C:\Source into C:\MyTEST\A\webroot\payrollservice.The source folder has two files 1. Web.config and 2. Web_PROD backup.
In the roll script there is a command to rename the config file. When I run the script first time, it is working fine. But when I run the script again , the renaming of file is not working. The root cause is that the remove directory command is not removing the folder. What need to be corrected here?
rem * STEP 1 taking backup of the folder
mkdir "C:\MyTEST\A\webroot\backup\b05232013v1\payrollservice"
xcopy "C:\MyTEST\A\webroot\payrollservice" "C:\MyTEST\A\webroot\backup\b05232013v1\payrollservice" /E /y /H
rem * STEP 2 remove physical folder
rmdir "C:\MyTEST\A\webroot\payrollservice"
rem * STEP 3 create physical folder
mkdir "C:\MyTEST\A\webroot\payrollservice"
rem * STEP 4 Copy sourcecode to Production boxes
xcopy "C:\Source" "C:\MyTEST\A\webroot\payrollservice" /E /y /H
rem * STEP 5 Rename teh config file
ren C:\MyTEST\A\webroot\payrollservice\Web.config WebLabbackup.config
ren C:\MyTEST\A\webroot\payrollservice\Web_PROD.config Web.config
pause
From Xcopy
/e : Copies all subdirectories, even if they are empty.
/y : Suppresses prompting to confirm that you want to overwrite an existing destination file.
/h : Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
Reference
Windows batch files: .bat vs .cmd?
From rmdir
/s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.
/q : Runs rmdir in quiet mode. Deletes directories without confirmation.
Figured it out. I need to use /s /q at the end of rmdir command.

xcopy syntax? (batch)

#echo off
xcopy /s/z/i Q:\U1210.exe C:\Users\jalozinski\Desktop\
START C:\Users\jalozinski\Desktop\U1210.exe
So this purpose of this code is to copy U1210.exe from the Q:\ drive to the desktop, then start the newly copied .exe. But for some reason it copies random folders and files from the Q:\ drive, and I don't know why. I have a feeling it has to do with the /s/z/i (i was trying these so it may be oen of them) or something to do with the filepath of the source. I feel like if I close the filepath it won't fix anything though.
This is batch, by the way. :I
Lets look at what you have for the XCOPY:
/S = Copies directories and subdirectories except empty ones.
/Z = Copies networked files in restartable mode.
/I = If destination does not exist and copying more than one file, assumes that destination must be a directory.
First I would try w/o the /S, because you don't need directories.
I would include /R (Overwrites read-only files.)
I would also include /Y (Suppresses prompting to confirm you want to overwrite an existing destination file.)
This is what I got working the way I think you want it:
#ECHO OFF
set source=Q:\U1210.exe
set dest=C:\Users\jalozinski\desktop\
xcopy %source% %dest% /Z /R /Y
start %dest%\U1210.exe
exit
#echo off
xcopy Q:\U1210.exe C:\Users\jalozinski\Desktop\
START C:\Users\jalozinski\Desktop\U1210.exe
that should be all you need
/s is copying all the subfolders
/i is assuming it is a directory (when in doubt)
/z is a preventitive measure if you have a very slow computer
so you should not need any of those commands

Resources