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

Tags: , , , ,

Vbscript to find latest file

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-11-2009
BoanHed's Avatar
Member
 
Join Date: Feb 2006
Posts: 108
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
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 1,486
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


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
Vbscript find replace help Ingmar1979 Software Development 2 09-07-2009 04:33 PM
How can i drag and drop another file on top of the VBScript file Dharmesh Arora Software Development 2 01-06-2009 09:53 PM
Issues when launching a vbscript file from hta interface file Hari Server Scripting 3 14-04-2009 11:01 PM
How to run a .bat file with VBScript ? troy Software Development 4 17-10-2008 03:17 PM
VBscript to apply .reg file Damo_Suzuki Customize XP 7 04-05-2006 07:19 PM


All times are GMT +5.5. The time now is 10:46 PM.