FileCopy by Modified Date

FileCopy by Modified Date

Post by RGlhbmF » Thu, 15 Feb 2007 03:43:02

I'm looking for a script that seems rather simple but having difficulty
finding one. I need to pull the most recent copy of a file from server1 to
folders on server2 and Server3. There are several other text files in the
same directory. I only want the file that has a modified date of today or
Curent days date.... I need the script based on the files modified date
and not created date.
I am not familair with scripting and am having a difficult time find a
script based on the modified date.

Any help would be greatly appreciated.

FileCopy by Modified Date

Post by Jeffery Hi » Fri, 16 Feb 2007 00:59:14

Use the FileSystemObject to get the date last modified:

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.GetFile("c:\boot.ini")
WScript.Echo objFile.DateLastModified

This will get all files in folder S: that have been modified today:
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFldr=objFSO.GetFolder("S:\")
Set colFiles=objFldr.Files
For Each F In colFiles
' WScript.Echo & " " & f.DateLastModified
If Cdate(F.dateLastModified) >= Date Then
End If

Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified.
VBScript & Windows PowerShell Training -
Windows PowerShell? -



FileCopy by Modified Date

Post by dXJrZW » Fri, 16 Feb 2007 04:28:20

'source and destination folders paths
strSourceFolder = "C:\"
strDestFolder1 = "C:\test\"
strDestFolder2 ="C:\test1\"

fileToCopy = "none"

'create the File System Object
set fso = CreateObject _
set sourceFolder = fso.GetFolder _

'loop through all the files in the source folder
for each file in sourceFolder.Files

'query text files only
if LCase(Right (file.Name,4)) = ".txt" then
if fileToCopy = "none" then
set fileToCopy = file
elseif fileToCopy.DateLastModified < file.DateLastModified then
set fileToCopy = file
end if
end if
'fileToCopy has the most recent DateLastModified

if fileToCopy = "none" then
WScript.Echo "no txt files in the folder"
'check if fileToCopy has current day's day, month, and year
elseif _
day (fileToCopy.DateLastModified) = day (now) and _
month (fileToCopy.DateLastModified) = month (now) and _
year (fileToCopy.DateLastModified) = year (now) then
'if yes copy the file to dest folders
fso.CopyFile fileToCopy.Path, strDestFolder1, true
fso.CopyFile fileToCopy.Path, strDestFolder2, true
WScript.Echo "no files modified today"
end if