Solved

# MS Dos Command to Copy

Posted on 2011-09-28
355 Views
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
Question by:Samoin
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 8

Expert Comment

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

ID: 36717216
0

LVL 56

Expert Comment

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

LVL 1

Author Comment

ID: 36717475
@billprew

Can you please forward me the sample script.

Thanks
0

LVL 56

Accepted Solution

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

~bp
0

LVL 56

Expert Comment

ID: 37059278

~bp
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
###### Suggested Courses
Course of the Month4 days, 7 hours left to enroll