Volser Posted April 4, 2006 Share Posted April 4, 2006 (edited) Hello people,I'm having a problem with a script I just wrote. I hope someone can fix my problem.I'm trying to copy files to a new location if they are older than 3 days.On Error Resume Next Dim oFSO Dim sDirectoryPath Dim oFolder Dim oFileCollection Dim oFile Dim iDaysOld iDaysOld = 3 Set oFSO = CreateObject("Scripting.FileSystemObject") sDirectoryPath = "C:\testfolder" set oFolder = oFSO.GetFolder(sDirectoryPath) set oFileCollection = oFolder.Files For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then oFSO.CopyFile "C:\testfolder\*.*", "D:\test2", OverwriteExisting End If Next Set oFSO = Nothing Set oFolder = Nothing Set oFileCollection = Nothing Set oFile = NothingMany thanks Edited April 4, 2006 by Volser Link to comment Share on other sites More sharing options...
Yzöwl Posted April 4, 2006 Share Posted April 4, 2006 Here's yours fixedOn Error Resume NextDim oFSODim sDirectoryPathDim oFolderDim oFileCollectionDim oFileDim iDaysOldiDaysOld = 3Set oFSO = CreateObject("Scripting.FileSystemObject")sDirectoryPath = "C:\testfolder\"set oFolder = oFSO.GetFolder(sDirectoryPath)set oFileCollection = oFolder.FilesFor each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then oFSO.CopyFile oFile, "D:\test2\", OverwriteExisting End IfNextSet oFSO = NothingSet oFolder = NothingSet oFileCollection = NothingSet oFile = NothingOr you could try this!Dim fso, f, f1SrcDir = "C:\testfolder\"DesDir = "D:\test2\"MorOld = 3Set fso = CreateObject("Scripting.FileSystemObject")Set f = fso.GetFolder(SrcDir)For Each f1 in f.Files If DateDiff("d", f1.DateLastModified, Now) > MorOld Then fso.CopyFile f1, DesDir, True End IfNextSet fso = NothingSet f = Nothing Link to comment Share on other sites More sharing options...
Volser Posted April 5, 2006 Author Share Posted April 5, 2006 Thanks for posting an new one. I just wanted to post my own fix. I just made it and finnaly it works like it shut.'On error resume next Dim oFSO Dim sDirectoryPath Dim oFolder Dim oFileCollection Dim oFile Dim iDaysOld iDaysOld = 3 Set oFSO = CreateObject("Scripting.FileSystemObject") sDirectoryPath = "C:\testfolder" strTarget = "D:\test2\" set oFolder = oFSO.GetFolder(sDirectoryPath) set oFileCollection = oFolder.Files Const OverwriteExisting = TRUE For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then Set iFSO = CreateObject("Scripting.FileSystemObject") iFSO.CopyFile oFile, strTarget, OverwriteExisting End If Next For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then oFile.Delete(True) End If Next Set oFSO = Nothing Set iFSO = Nothing Set oFolder = Nothing Set oFileCollection = Nothing Set oFile = Nothing Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now