I am trying to copy the folders and files created between the date range. But this following command looks like copying everything from the source ignoring the date range. What could be wrong?
robocopy c:\source c:\destination /E /dcopy:t /MAXAGE:20100101 /MINAGE:20110101
The /maxage and /minage switches in robocopy seem to refer to the modified date. It is not obvious from the documentation but if you try for yourself you can easily verify that. There are no switches for the creation date so I believe the only solution here is powershell if the difference in performance is acceptable to you.
Related
How can I copy all files/folders in a directory using a batch file but omit one? I know I could always delete it after the fact but it is an extremely large folder and I don't want to waste the time copying it. There are numerous files in the location I want to copy so doing it one individually would be unrealistic. Thank yoU!
robocopy "source" "destination" files_to_copy.ext /e /xd "folder_to_exclude"
robocopy is an upgraded version of xcopy, thus, is more useful. You can check the complete usage by typing robocopy /?, or from the microsoft docs, or from ss64.
EDIT: Almost forgot, robocopy accepts wildcards, so you can type *.* to copy every files. The line I suggest already have the option /e, which will copy all subfolders, even the empty ones. /xf:file_to_exclude.ext can also be used to skip a specific file type, eg. /xf:"*.txt" to exclude all the .txt files.
xf is used to exclude files, xd to exclude folders.
I want to copy files and folders in a directory to another folder excluding sub-folders with files contains it, as for example I have a large number of files for node_modules directory which like 100Mb with 50K+ files, that I don't need to copy.
I tried using xcopy like this :
xcopy . c:\inetpub\CIVEBuildCentral\UI\. /Y /S /EXCLUDE:CIVE\UI\elist.txt
and elist.txt contains :
\node_modules\
But no luck, and its really annoying syntax and I don't see its optimal to check-in such a useless file for this case.
Any idea how to solve this?
Well, after searching I found a similar question in StackOverflow but was not so helpful for my case:
Xcopy Command excluding files and folders ( its marked as duplicated but actually it's not really duplicated, it is the different case even if answer seemed the same way, and found no answer for my case anyway)
But I found that if you using Windows 7 or later, you can use robocopy instead, found its so powerful tool compared to old man xcopy, and no need to dirty work for exceptions, the command to achieve what I need replaced xcopy with :
robocopy . c:\inetpub\CIVEBuildCentral\UI\. /IS /S /XD node_modules
For full documentation for it, you can see this link: http://ss64.com/nt/robocopy.html
Solved my issue, and the output of the result was so nice, clear, and well formatted.
I have a list of file extensions I need to collect all the files of from a particular directory while maintaining attributes, timestamps etc. which has resulted in my usage of Robocopy. I'm hoping someone can suggest a more efficient method than my current solution?
At present I copy these files using the following command into an "unprocessed" directory:
robocopy %Directory1% "%Directory2%\unprocessed" /Z /E /copy:dat *.pst *.ost *.doc *.docx *.pdf *.docm *.xls *.xlsx *.ppt /log+:%Directory%.txt
The individual collected files from inside the "unprocessed" directory are then sorted to individual folders named after each file extension and created at the same level as the "unprocessed" directory, again using individual Robocopy commands:
robocopy "%directory2%\unprocessed" %directory2%\pst *.pst /Z /E
...
...
robocopy "%directory2%\unprocessed" %directory2%\ppt *ppt /Z /E
As you can appreciate, this results in unnecessary iterations of the "unprocessed" directory multiple times. I'm unable to copy files straight to the final resting places due to the nature of robocopy so I'm hoping someone can suggest a more suitable solution that will still allow file attributes to remain intact.
(I apologise in advance that this could turn into a discussion as opposed to someone being directly able to answer this)
Given the % signs in your examples, it looks like you're probably running this as part of a batch file. Either way, if you have the environment variables defined, you could use the following:
Command line:
for %e in (pst ost doc docx pdf dcom xls xlsx ppt) do robocopy "%Directory1%" "%Directory2%\%e" /Z /E /copy:dat *.%e /log+:%Directory%.txt
Bat file:
for %%e in (pst ost doc docx pdf dcom xls xlsx ppt) do robocopy "%Directory1%" "%Directory2%\%%e" /Z /E /copy:dat *.%%e /log+:%Directory%.txt
One other thing to note: You'll probably end up with all docx files in both doc and docx, likewise xlsx would end up in both xls and xlsx. Windows always picks up longer extensions with 3 character extensions.
We have a file share that has a directory containing all of our build version direcotries named like this
WebApp_20140702.1 first number being date second number being the build count for that date
these are then contained in the following directory
\\server\share\product\
What i need to do from a virtual machine is create a batch file that can check the target location on my vm ie. c:\product\ see if it has the latest version from the network share either by comparing the file names or dates, then copy the new version and delete the old if necessary.
So far i can copy the folder over using xcopy but that's about the extent of my dos/batch file knowledge iv had a look around for a while but haven't been able to see anything that i can use
This is what i have so far, as you can see though i dont know how to do the comparison between the two directories as explained above.
xcopy "\\server\share\webapp" "c:\users\username\desktop\webapp" /E /K
I did try to use just /D at the end and just copying the directories from \\server\share\product\ that had a later date than the target but it ended up just copying the whole directory.
EDIT : to make my self clear
i need to find out if i have the latest sub directory but no matter what i do it always copies all the sub directories from \\server\share\product\
ie. the \\server\share\WebApp directory will have the following sub dirs
..\WebApp_20140628.1\
..\WebApp_20140628.2\
..\WebApp_20140703.1\
and my vm will have the directory
c:\product\WebApp_20140628.2\
Now i need to be able to go into the file share see that it has a more up to date subdirectory i need to copy that directory to my vm and then delete the older one from my vm so i would then have
c:\product\WebApp_20140703.1\
OK i eventually found another question that wanted to do a similar thing and the answer worked exactly as i wanted it
Question can be found here: How to get the most recent file using a batch script in windows
i had to use xcopy instead of the copy used in the answer for the above question. here is my solution as well in case anyone needs something similar
(z is the mapped version of the network share i talk about in my question)
pushd "z:\WebApp\"
for /f "tokens=*" %%a in ('dir/b /od') do set newest=%%a
xcopy /e /k "%newest%" "c:\product\"
popd
im not sure if i actually need the popd command as i believe it just goes back to the directory set in the pushd command
I'm trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this:
If file is in both source and destination and they are different, source file will be copied
If file is in both source and destination and they are the same, nothing will be copied
If file is only in the source, source file will be copied
If file is only in the destination, destination file will be deleted.
I'm still new to shell scripting and I'm not sure how I could implement this. Any ideas? Windows batch scripts would be better, but shell scripts that run on Cygwin are also fine.
Take a look at rsync tool - it was designed to minimize traffic during files synchronization.
Also, probably "cp" with "-u" argument will be useful:
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing
For windows batch scripting xcopy (native to windows) or robocopy (a free download in windows) both work extremely well.
An example xcopy script (in a .bat file):
#echo off
:: /L = list only.
:: /v=Verify, /y=No prompting /s=subdirs /z=Network mode (supports bad)
:: /i=Tells xcopy dest is folder /f=Display names /d=Copy only changed
echo Backing up projects...
xcopy e:\projects h:\projects /V /Y /S /Z /I /F /D
It will even support orphaned files (if you delete something from your source you no longer need a copy in the backup). Xcopy is typically fine for your needs until you deal with sync between NTFS and Fat32 file systems - the later only has a 2 second resolution and problems with daily savings time so you occasionally run into issues: (a) on time change day you might not get a backup of a changed file - depends on change-regularity of course or you might get a backup of all files even though none have changed (b) because of time resolution some files may backup even though they haven't changed.