1

I am trying to write a vbs to copy the latest modified files to another location. The script goes like this

Option Explicit
Dim oFSO, oFolder, oFile
Dim vSourcePaths ,vDestinationPaths

vSourcePaths = "C:\xampp\htdocs\lgmsuploads"
vDestinationPaths = "S:\LGMSUPLOADS"

Set oFSO = CreateObject("Scripting.FileSystemObject")
oFolder = oFSO.GetFolder(vSourcePaths)

For Each oFile In oFolder.Files
    If oFile.DateLastModified < DateAdd("h", -24, Now) Then
        oFSO.CopyFile vSourcePaths & "\" & oFile.Name, vDestinationPaths & "\" & oFile.Name                       
    End If
Next

But this gives the following error

Error Message

Please help...

1 Answer 1

1

You should use Set statement to assign an object reference to a variable as follows:

Set oFolder = oFSO.GetFolder(vSourcePaths)

However, your script will copy files with oFile.DateLastModified 24 hours ago and before.

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly I have modified the condition so as to copy files of last 24 hours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.