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.name & " " & f.DateLastModified
If Cdate(F.dateLastModified) >= Date Then
WScript.Echo F.name
End If
Next

--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
VBScript & Windows PowerShell Training -
www.ScriptingTraining.com/classes.asp
Windows PowerShell? - www.SAPIENPress.com/powershell.asp

blog: http://www.yqcomputer.com/
blog: http://www.yqcomputer.com/

 
 
 

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 _
("Scripting.FileSystemObject")
set sourceFolder = fso.GetFolder _
(strSourceFolder)

'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
next

if fileToCopy = "none" then
WScript.Echo "no txt files in the folder"
WScript.Quit
'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
else
WScript.Echo "no files modified today"
end if
--
urkec