Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open lastmodified file in a folder
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Can anyone send me the script for "to open the last modified file in a folder"
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi Vimal,
Hope you can make use of this:
Code:
Option Explicit
Dim objFSO, objFile, objFolder, FolderToScan
Dim c, i, j
FolderToScan = "D:\EricData\vbs"
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFolder = objFSO.GetFolder(FolderToScan)

Dim arrFileName(), arrFileDateLastModified()

c = 0
For Each objFile In objFolder.Files
    c = c + 1
    
    ReDim Preserve arrFileName(c)
    arrFileName(c) = objFile.Name

    ReDim Preserve arrFileDateLastModified(c)
    arrFileDateLastModified(c) = objFile.DateLastModified
Next

For i = 1 To c
    For j = i + 1 To c
        If arrFileDateLastModified(i) < arrFileDateLastModified(j) Then
            SwapValues arrFileName(i), arrFileName(j)
            SwapValues arrFileDateLastModified(i), arrFileDateLastModified(j)
        End If
    Next
Next

For i = 1 To c
    MsgBox "File: " & arrFileName(i) & "  Last mod: " & arrFileDateLastModified(i)
Next

Sub SwapValues(ByRef v1, ByRef v2)
    Dim vTemp
    vTemp = v1
    v1 = v2
    v2 = vTemp
End Sub
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a folder from within a reusable action. sd3 2 3,182 06-18-2013, 03:20 PM
Last Post: learnQtptips
Exclamation How to open a text file through VB scripting.? qtplearner88 2 4,453 06-22-2012, 01:51 PM
Last Post: ravs@788
  How can i write a script in QTP to poll a folder for a new file? geethwind 5 5,436 05-19-2011, 07:04 PM
Last Post: deepaksporty
  Recently Created File or Folder bfakruddin 3 3,128 12-29-2009, 03:40 AM
Last Post: jsknight1969
  Unable to open a file using open file dialog windows vista umer830 10 14,064 12-21-2009, 01:48 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)