Results 1 to 4 of 4

Thread: Vbscript to find latest file

  1. #1
    Join Date
    Feb 2006
    Posts
    185

    Vbscript to find latest file

    I am looking for vb script to find the file. The script should first scan the specific location and then go in to the any subfolder in the directory and then scans each folder for files. I will then go and perform some other tasks with this file.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Vbscript to find latest file

    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Folcan = "d:\"
    
    Set objFolder = obj1.GetFolder(Folcan)
    
    NewestFile = ""
    NewestDate = #1/1/1970#
    
    For Each objFile In objFolder.Files
        If File1.DateLastModified > NewestDate Then
            NewestDate = File1.DateLastModified
            NewestFile = File1.Name
        End If
    Next
    
    WScript.Echo NewestFile

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Vbscript to find latest file

    Try this code to find latest file in vbscript :
    Code:
    Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
    strParent = "\\test\test1"
     
    ScanDirectory (objFSO.Folder1 (strParent)
     
    Set objFSO = Nothing
    wscript.quit
     
    Sub ScanDirectory (Folder2)
      ScanFiles Folder2
      For Each fld in Folder2.SubFolders
        ScanDirectory fld
      Next
    End Sub
     
    Sub ScanFiles (Folder2)
      Dim Oldest
      For Each fil in Folder2.Files
        If objFSO.GetExtensionName(f1) = "bak" Then
          If Oldest = "" Then Oldest = f1.DateCreated
          If F1.DateCreated > Old=  F1.DateCreated
        End If
      Next
    End Sub

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Vbscript to find latest file

    Code:
    dim sMostRecent, dMostRecent
    MostRecent("D:\Temp")
    fileScript.Echo sMostRecent, dMostRecent
    Sub MostRecent (Folder1)
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    dMostRecent = 0
    sMostRecent = ""
    For Each oFile In oFSO.GetFolder(sFolder).Files
    dFileDate = oFile.DateLastModified
    If dFileDate > dMostRecent Then
    dMostRecent = dFileDate
    sMostRecent = file2.Path
    End If
    Next
    End Sub

Similar Threads

  1. How to run a .bat file with VBScript ?
    By troy in forum Software Development
    Replies: 8
    Last Post: 29-06-2012, 10:55 AM
  2. Replies: 4
    Last Post: 21-03-2012, 05:01 AM
  3. Vbscript find replace help
    By Ingmar1979 in forum Software Development
    Replies: 2
    Last Post: 09-07-2009, 04:33 PM
  4. What happens when you drag and drop a file on top of a vbscript
    By Dharmavira in forum Software Development
    Replies: 2
    Last Post: 01-06-2009, 10:00 PM
  5. How can i drag and drop another file on top of the VBScript file
    By Dharmesh Arora in forum Software Development
    Replies: 2
    Last Post: 01-06-2009, 09:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,673,355.23957 seconds with 17 queries