PDA

View Full Version : VBA: get specific folder from the path



dpatel
06-12-2013, 08:32 AM
Hello,

How can i get the last modified date folder name to pass on the variable.
Details:
- I have several folders by date format "DDMMYYYY" on specific path with multiple files in it.

I would like to right the script to check
- if folder(s) last modified date is today (DDMMYYYY) with files then Exit the script
otherwise
- check if folder(s) last modified date is less than today (DDMMYYYY) with files then get the folder name and pass it to one variable or just display as msgbox.

can someone please help me to write the script?

Thanks

mancubus
06-12-2013, 01:15 PM
hi.

this can get you started...

folder:

Sub test_folder_date()
With CreateObject("Scripting.FileSystemObject")
With .GetFolder("C:\Users\Me\MyFiles")
MsgBox .DateLastModified
MsgBox .DateLastAccessed
End With
End With
End Sub


file:

Sub test_file_date()
With CreateObject("Scripting.FileSystemObject")
With .GetFile("C:\Users\Me\MyFiles\TestFile.xlsm")
MsgBox .DateLastModified
MsgBox .DateLastAccessed
End With
End With
End Sub

Kenneth Hobs
06-12-2013, 05:31 PM
Sub ken()
Dim s As String
s = CreateObject("Wscript.Shell").exec("cmd /c dir x:\ /ad /o:-d /b").StdOut.ReadAll
If s = vbNullString Then Exit Sub
s = Split(s, vbCr)(0)
MsgBox s, vbInformation, CStr(CreateObject("Scripting.FileSystemObject").GetFolder("x:\" & s).DateLastModified)
End Sub