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.
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.
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
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
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
Bookmarks