|
| |||||||||
| Tags: directory, files, script, subfolder, vb script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| |||
| |||
| 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
| |||
| |||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 | 6 | 28-11-2011 06:01 PM |
| 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 | Windows Server Help | 3 | 14-04-2009 11:01 PM |
| VBscript to apply .reg file | Damo_Suzuki | Windows XP Support | 7 | 04-05-2006 07:19 PM |