views:

326

answers:

1

Hi All

I need to get all the modified files inside a folder including the subfolders inside it, and copy them to another folder. How can it be done using VBScript or any other way to achieve this?

Thanks in advance,
Bibhu

+1  A: 

try this (copy files modified less than 24 hrs ago )

Set objFS = CreateObject("Scripting.FileSystemObject")
''# Directory to scan
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
Go( objFolder)

Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
        Go eFolder
    Next
    For Each strFiles In objDIR.Files
        strFileName = strFiles.Name
        strFilePath = strFiles.Path         
            If DateDiff("h",strFile.DateLastModified,Now) < 24 Then
           objFS.CopyFile strFolder&"\"&strFileName,"c:\tmp"
        End If 

    Next    
  End If  
End Sub
ghostdog74
Close, but what happens if multiple files from different source directories have the same name? Is it ok to lose the folder information anyway?
AnthonyWJones
OP has to make provision to create folders at the destination if he deems it necessary.
ghostdog74
it was of great help, ve to tweak a bit, but worked fine...anthony, i know about the same name issue but as far as my folder stucture is concerned, it will not have same names..so thanks guys for your help :)