Solved

MS Dos Command to Copy

Posted on 2011-09-28
6
317 Views
Last Modified: 2012-05-12
Hi Experts,

I'm trying to using ms dos to copy files between two given dates, is there a specific command for that? I already tried using /D with xcopy but it copies files changed on or after the specified date. Any help will be greatly appreciated.

Thanks
0
Comment
Question by:Samoin
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:moonie42
ID: 36717206
Use robocopy as it supports a minage and maxage flag:
robocopy c:\source c:\destination *.* /MAXAGE:20101231 /MINAGE:20111001
0
 
LVL 8

Expert Comment

by:moonie42
ID: 36717216
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36717461
Agreed there is no baseline DOS command to do the date range copy you seek.  ROBOCOPY is a good alternative, which is a free addon utility Microsoft create a while back and made available through windows resource kits.  It is now included as part of Windows 7 also.  But depending on your Windows version you may have to download and install it.

Since you will need to run something other than just DOS commands to do this, another approach would be a rather small vbscript that could do the date range checking and copy the matching files easily.  Let me know if you are interested in seeing a sample of that approach.

~bp
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:Samoin
ID: 36717475
@billprew

Can you please forward me the sample script.

Thanks
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36719699
Here's the basic idea, see if this makes sense.  You would run it with a command line from BAT as follows:

cscript //nologo EE27345823.vbs c:\from c:\to 9/1/2011 9/29/2011

' Define file system object, get from folder handle
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Make sure all 4 parms provided
If Wscript.Arguments.Count < 4 Then
   Wscript.Echo "Usage: cscript yourfile.vbs <from folder> <to folder> <from date> <to date>"
   Wscript.Quit
End If

' Get from and to folders from command line
strFromDir = Wscript.Arguments(0)
strToDir = Wscript.Arguments(1)

' Make sure directory names end in backslash
If Right(strFromDir, 1) <> "\" Then strFromDir = strFromDir & "\"
If Right(strToDir, 1) <> "\" Then strToDir = strToDir & "\"

' Make sure they both already exist
If Not objFSO.FolderExists(strFromDir) Then
   Wscript.Echo "Usage: cscript yourfile.vbs <from folder> <to folder> <from date> <to date>"
   Wscript.Quit
End if
If Not objFSO.FolderExists(strToDir) Then
   Wscript.Echo "Usage: cscript yourfile.vbs <from folder> <to folder> <from date> <to date>"
   Wscript.Quit
End if

' Get date range to process files from
datFromDate = CDate(Wscript.Arguments(2))
datToDate = CDate(Wscript.Arguments(3))

' Make sure the dates were entered in proper order
If datFromDate > datToDate Then 
   datFromDate = CDate(Wscript.Arguments(3))
   datToDate = CDate(Wscript.Arguments(2))
End If

' Process all files in the from folder, check if they are in the date range, copy if so
Set objFromDir = objFSO.GetFolder(strFromDir)
For Each objFile In objFromDir.Files
   if objFile.DateLastModified >= datFromDate And objFile.DateLastModified <= datToDate Then
      Wscript.Echo "Copying [" & objFile.Path & "] to [" & strToDir & objFile.Name & "]"
      objFile.Copy strToDir & objFile.Name
   End If
Next

Open in new window

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37059278
Thanks much, glad that helped.

~bp
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now