Announcement

Collapse
No announcement yet.

VBscript with multiple functions

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBscript with multiple functions

    I have created a script to look for the newest file in a folder, check if the file exists and delete it if it does and then at last copy it.
    Code:
    dim filesys
    dim filesystem
    Set filesys=CreateObject("Scripting.FileSystemObject")
    set filesystem=CreateObject("Scripting.FileSystemObject")
    set oFolder=createobject("scripting.filesystemobject").getfolder("C:\my path")
    For Each aFile In oFolder.Files
        If sNewest = "" Then
            Set fNewest = aFile
            sNewest = aFile.Name
        Else
            If fNewest.DateCreated < aFile.DateCreated Then
                Set fNewest = aFile
            End If
        End If
    Next
    
    filesys.CreateTextFile "X:\my path\" & fNewest.Name , True
     If filesys.FileExists("X:\my path\" &fNewest.Name ) Then
      filesys.DeleteFile "X:\my path\" &fNewest.Name
     End If
    
    If filesystem.FileExists("C:\my path\" & fNewest.Name) Then
     filesystem.CopyFile "C:\my path\" & fNewest.Name, "X:\my path\"
    End if
    I would like to change the script so it merges the new copied file with the one existing in the destination folder. I'm having a little trouble figuring out how to merge files in vbs.
Working...
X