* Windows 2000 DOS Script To Copy Files After a Specific Date *

benc007
benc007 used Ask the Experts™
on
I don't have xcopy for Windows 2000.

I want to write a super simple DOS bat file to do this daily:
1) Copy all files in C:/SourceDirectory and in C:/SourceDirectory2 to D:/DestinationDirectory that are created or modified after and including June 1, 2017.
2) Create a copy of  D:/DestinationDirectory and rename it as DestinationDirectory_MMDDYY where MMDDYY is the current month, day and year.

How do I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
xcopy does what you need. copy does not. So if you do not have xcopy, you would have write a little program to do what you wish.

Author

Commented:
Xcopy isn't on Windows 2000.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Xcopy is no longer in the Windows 2000 Resource Kit that Microsoft has posted — and I do not recommend downloading it from non-MS sites. But Robocopy is in the Microsoft-posted Windows Server 2003 Resource Kit, and according to this EE Accepted Solution, the Robocopy.exe from the WS2003 Resource Kit will work on W2K. I haven't tried it myself, but it's worth a shot. Robocopy is more robust than Xcopy and can do what you want in conjunction with a batch file. Regards, Joe
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
I know xcopy is not on such an old system. Copy does not have the options. I don't know about robocopy.

Author

Commented:
Joe Winograd - RE: Robocopy is in the Microsoft-posted Windows Server 2003 Resource Kit

I opened the link and downloaded rktools.exe but it tries to install and updates a bunch of Windows files. How can I just download Robocopy.exe?
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
I don't think it works for such an old product.

If you wish to run new things, you need to modernize. Otherwise you cannot do what you want.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Robocopy should work fine on your W2K system, but there's no way that I'm aware of to extract it from the Resource Kit install file. I'm testing an alternative approach for you in my W2K sandbox and will post back here as soon as I'm done testing (I prefer to recommend solutions that I've personally tested and confirmed). Regards, Joe
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Well, it's a good thing I tested it — doesn't work. My idea was to install Robocopy from the link in its MS TechNet Utility Spotlight article:
https://technet.microsoft.com/en-us/library/2006.11.utilityspotlight.aspx

The purpose of that article is to document the Robocopy GUI, and it has an install link in it. My idea/hope was that it would install the robocopy.exe command line executable that is called by the GUI program. Sadly, it doesn't. The only executable installed is RobocopyGW.exe, which is the GUI program — obviously, Robocopy is compiled into that EXE. There's more bad news. I tried to install the Resource Kit (rktools.exe) on my W2K system, but it said, "This product requires Windows XP or a later version..."

Now for the good news — if you have an XP system on which to install the Resource Kit (rktools.exe). I just did that and then copied robocopy.exe (which was installed in c:\Program Files\Windows Resource Kits\Tools\, along with the documentation for it — robocopy.doc) to the W2K system — works perfectly! But I don't know if such usage is in license compliance — that's your call. Regards, Joe
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You are allowed to copy RoboCopy around in your company, as long as you have obtained it legally, so there is no legal issue with that procedure, Joe. And what I would do too.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Qlemo,
Thanks for that info — very much appreciated! I always want to be in software license compliance, so that's really good to know. Regards, Joe

Author

Commented:
Qlemo & Joe Winograd

How do you use Robocopy to do this?

1) Copy all files in C:/SourceDirectory and in C:/SourceDirectory2 to D:/DestinationDirectory that are created or modified after and including June 1, 2017.

2) Create a copy of  D:/DestinationDirectory and rename it as DestinationDirectory_MMDDYY where MMDDYY is the current month, day and year.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
For 1) you need two RoboCopy calls. You can only provide a single "root" folder.
robocopy  C:\SourceDirectory D:\DestinationDirectory /s /minage:20170601
robocopy  C:\SourceDirectory2 D:\DestinationDirectory /s /minage:20170601

Open in new window

2) requires to set the date part by other means. RoboCopy can't do that. But seriously - don't use US date format. The proper format is yyyymmdd.
robocopy D:\DestinationDirectory D:\DestinationDirectory_%date:~-4%%date:~-10,2%%date:~-7,2% /s

Open in new window

However, you will collect old files in D:\Destination - files which have been in one of the source folders, but are deleted or renamed meanwhile. I'm also not getting why we cannot just rename the destination folder (or use the correct one from start).
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
I have the same question as Qlemo — why not make a directory called D:\DestinationDirectory_MMDDYY and copy from the two source directories into that? Or is there some reason why you want to keep building up the files daily in D:\DestinationDirectory?

Anyway, I see that he has given you the Robocopy calls. But there's a problem with using the %date% variable because its value depends on the region settings. For example, on my system, echo %date% gives me this:

Tue 06/20/17

So Qlemo's echo %date:~-4%%date:~-10,2%%date:~-7,2% gives me this:

0/17e 6/

A way to do it that works with all region settings is this:

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set datetoday=%%j
set datetoday=%datetoday:~4,2%-%datetoday:~6,2%-%datetoday:~2,2%

Open in new window

(I did not write that for /F statement myself — I'd like to credit the author, but I can't. It's been sitting in my bag-of-tricks for a while.)

An echo %datetoday% after the above should give MMDDYY on all systems. I also agree with Qlemo about YYYYMMDD. The code for that uses the same for /F statement as above, but this set statement instead:

set datetoday=%datetoday:~0,4%%datetoday:~4,2%%datetoday:~6,2%

Open in new window

And if you would like hyphens for better readability, i.e., YYYY-MM-DD, here's the set statement:

set datetoday=%datetoday:~0,4%-%datetoday:~4,2%-%datetoday:~6,2%

Open in new window

Also, I think Qlemo has the wrong age option. The Robocopy Help says this:

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.

So /minage:20170601 will exclude files newer than 20170601. But those are the files that you want to include (plus 20170601 itself), not exclude. So you want the option /maxage:20170601, which will exclude files older than 20170601, meaning it will include files dated on and after 20170601.

So, if you like idea of making a directory with the date and copying straight into that, the calls should be:

robocopy C:\SourceDirectory D:\DestinationDirectory_%datetoday% /s /maxage:20170601
robocopy C:\SourceDirectory2 D:\DestinationDirectory_%datetoday% /s /maxage:20170601

Open in new window

If you'd like it also to copy empty directories, change the /s option to a /e instead (but note that maxage will not apply to the directories).

You should precede those calls with making the new directory, as follows:

mkdir D:\DestinationDirectory_%datetoday%

Open in new window

I think that's it. Regards, Joe
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
All points valid, Joe ... I misread the age request, you are correct, it needs to be /maxage.
In your case the adjusted date extraction expression is %date:~-2%%date:~-8,2%%date:~-5,2%.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
%date:~-2%%date:~-8,2%%date:~-5,2%
To be clear, that gives YYMMDD on my system. For MMDDYY it is:
%date:~-8,2%%date:~-5,2%%date:~-2%

But, again, that depends on regional settings. For example, in some regions the order is DDMM instead of MMDD, so the offsets for the %date% variable would need to be changed. That's the advantage of the wmic approach, although on a specific system where you always know what the structure of %date% is, it's a lot easier to deal with that — just a matter of the offsets. Regards, Joe

Author

Commented:
There are spaces in my source directory names and paths, and there are spaces in my destination directory names and paths.  Should I use single or double quotes in the source and directory parameters?
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Double. So something like this:

mkdir "D:\Destination Directory with spaces _ %datetoday%"
robocopy "C:\Source Directory with spaces" "D:\Destination Directory with spaces _ %datetoday%" /s /maxage:20170601

Open in new window

FYI, a single quote is valid in a file name — hence, the need for the double quote. :)

Author

Commented:
I pre-created the destination directory so only used the second line of code but both single and double quotes didn't work.

robocopy "C:\Source Directory with spaces" "D:\Destination Directory with spaces" /s /maxage:20170601

Error: The filename, directory name, or volume label syntax is incorrect.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Of course you used your real-world folder names?!
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're doing it wrong. The double quotes work fine. Here's the output from my test:

robocopy "C:\Source Directory with spaces" "D:\Destination Directory with spaces" /e /maxage:20170601

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows

-------------------------------------------------------------------------------

  Started : Wed Jun 21 12:46:23 2017

   Source : C:\Source Directory with spaces\
     Dest : D:\Destination Directory with spaces\

    Files : *.*

  Options : *.* /S /E /COPY:DAT /MAXAGE:20170601 /R:1000000 /W:30

------------------------------------------------------------------------------

                           1    C:\Source Directory with spaces\
            New File                5890        chrome failed install on w10.gif
100%

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :     5.7 k     5.7 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :             1963333 Bytes/sec.
   Speed :             112.342 MegaBytes/min.

   Ended : Wed Jun 21 12:46:23 2017

You likely specified the wrong source and/or destination directories. Regards, Joe

Author

Commented:
robocopy "C:\Source Directory with spaces\" "D:\Destination Directory with spaces\" with the trailing \ and without /e doesn't work

robocopy "C:\Source Directory with spaces" "D:\Destination Directory with spaces" /e /maxage:20170601 is working  =)

It's taking awhile since there's over 3 millions files in the source directory, and I only want to copy around 100 new or updated files daily.  Do you have any suggestions on how to speed up the copy process?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
RoboCopy has special treatment of \" - you need to make sure you do not end a path with a backslash.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Regarding speed, there is nothing you can do but to remove those 3M files. This will always be a pain, as RoboCopy is not able to use an index or similar, and so has to look thru all folder info to detect if there are newer files. Very bad design, this folder content ...
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
> with the trailing \ and without /e doesn't work

Of course. You should study the Robocopy syntax and experiment with it — robocopy /? will give you its Help output (full syntax) and there are plenty of websites that give examples, such as SS64.

> is working  =)

Yes, I'm sure. :)  Glad to hear it.

> Do you have any suggestions on how to speed up the copy process?

Don't have 3 million files in a single directory — that's insane! Create a subfolder structure so that each folder has a reasonable number of files in it.

Author

Commented:
Unfortunately, I can't change the structure of the source directory since a lot of other code accesses this directory.

Since Robocopy only copies the new files, and has to check the datetimestamps of each file, I wonder if it's the same speed to copy the entire directory instead of using the maxage parameter?

Author

Commented:
I would like to test to see if it's faster to use maxage or just copy all of the files from the source directory.

What is the syntax to add a timer so I know how long the copying process takes?  

/e outputs the lists of files copied at the end of the process.  How can I just output the number of files copied into a .txt file and not show this in the cmd output?
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
I've never done a test on that, but my gut says that it will take much longer to copy the files than to check the date/time stamps, i.e., much better to avoid copying the old files.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You are really asking that? No, scanning file and folder (meta) data is much faster than having to access the real files associated with it. Imagine a very large list with file names, folder names they are in, and such info as size and timestamps. The issue is the list is not sorted for a timestamp, but for folder and file name. That does not help in speeding up this particular job.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Logging into file: /Log:YourFileName.txt
Look at the other options to remove file detail info, and only get the summary.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> add a timer so I know how long the copying process takes

Lot of ways to do this. You could simply add this in your batch file before and after the Robocopy call:

echo %date% %time%

> How can I just output the number of files copied into a .txt file and not show this in the cmd output?

Please read the Help output and come back here when you don't understand something. Let us know what you've tried...what works...what doesn't work. For this issue, read the Help section that says, ":: Logging Options :". If you want someone to develop the entire solution for you, I suggest creating a project in Gigs. Regards, Joe

Author

Commented:
robocopy "C:\Source Directory with spaces" "D:\Destination Directory with spaces" /e /maxage:20170601 /LOG:RoboCopyLog_%datetoday%.txt

RoboCopyLog_.txt was created but without the date.  What am I missing?
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Probably means that the %datetoday% variable is null. Did you set the value of the %datetoday% variable? Put in an echo %datetoday% statement before the robocopy statement.

I'm leaving my office now for a few hours. I'll check back into the thread when I return to see how you're doing. In the meantime, I leave you in the extremely capable hands of Qlemo. :)

Author

Commented:
Joe Winograd - I appreciate your help.  

echo %datetoday% has no value.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> echo %datetoday% has no value.

OK, exactly what I expected. You need to set its value in the batch file before using it. For example, this is likely to get you MMDDYY (but note the discussion above about region settings):

set datetoday=%date:~-8,2%%date:~-5,2%%date:~-2%

Open in new window

Regards, Joe

Author

Commented:
Thank you Joe Winograd and Qlemo!!
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome. I'm glad it's working now. Happy to help. Regards, Joe

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial