Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Vbscript to find latest file

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-11-2009
Member
 
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.

Reply With Quote
  #2  
Old 23-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #3  
Old 23-11-2009
Member
 
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
Reply With Quote
  #4  
Old 23-11-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Vbscript to find latest file"
Thread Thread Starter Forum Replies Last Post
How to run a .bat file with VBScript ? troy Software Development 8 29-06-2012 11:55 AM
Issues when launching a vbscript file from hta interface file Hari Windows Server Help 4 21-03-2012 06:01 AM
Vbscript find replace help Ingmar1979 Software Development 2 09-07-2009 05:33 PM
What happens when you drag and drop a file on top of a vbscript Dharmavira Software Development 2 01-06-2009 11:00 PM
How can i drag and drop another file on top of the VBScript file Dharmesh Arora Software Development 2 01-06-2009 10:53 PM


All times are GMT +5.5. The time now is 05:30 PM.