Ok, I think I found here what you mean with %~dp
.
I think what you really want to do is this:
cd /D "%~dp0"
(!) But note that this will still not give you the right behaviour when you're trying to execute your batch while the current directory is on another drive as cd
doesn't change the active drive.
Edit: Apparently (thanks @Yoopergeek) you can add the /D
parameter to the cd
command to let it also change the active drive.
Robocopy is your friend in this. It has a flag that'll do exactly what you want.
robocopy c:\ f:\ /mir /r:1 /sec
That'll do a mirror copy, retrying open files once before moving on, and will also copy security. The mirror copy will also remove files from F:\ that no longer exist on C:\, which is something xcopy can't do. Also, after the first sync it'll only copy newer files.
If robocopy isn't a possibility for some reason, you can get kind of close with xcopy.
xcopy C:\*.* F:\*.* /S/E/H/D
That'll copy the entire C:\ structure to F:\, copy hidden files, and only copy newer ones. It won't remove files from F:\ that exist in C:\ though.
Edit:
Perhaps this'll do what you want:
for /D %D in (C:\User*\) do xcopy C:\User%D\*.* F:\User%D /s /e /d 08-01-2010
That'll iterate over all directories with User in them, and copy files newer than the first of August.
Best Answer
ps