Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Newest Subfolder

Status
Not open for further replies.

sourcelamp

Programmer
May 21, 2001
3
US
I am trying to access information created by an automated
program. The automated program creates folders and saves
files into them. I need to write a visual basic program
that will determine which is the newest subfolder created
in order to find the newest files.

In other words, let's say that the "base" folder structure
is c:\folder\sub1folder\sub2folder. The program may have
created several subfolder such as:

c:\folder\sub1folder\sub2folder\sub3folder1
c:\folder\sub1folder\sub2folder\sub3folder2
c:\folder\sub1folder\sub2folder\sub3folder3
c:\folder\sub1folder\sub2folder\sub3folder4
etc.

The vb program knows what the base folder is. It just
needs to determine which of the sub3folders is the newest,
or more recently created. I haven't been able to figure
out how to extract this information. Any help would be
appreciated.
 
Code:
Dim objFs as scripting.FileSystemObject
Dim objFolders as scripting.Folder
Dim objFolder  as scripting.Folder
Set objfs = CreateObject("Scripting.FileSystemObject")
Do
    On error resume next
    Set objFolder = objfs.GetFolder(strFoldername)
    if err.number <> 0 then exit do
    Set objFolders = objFolder.SubFolders
    if err.number <> 0 then exit do
    For each objFolder in objFolders
        ... = objfolder.DateCreated
        ... = objfolder.DateModified
        ... = objfolder.DateLastAccessed
        if err.number <> 0 then exit do
    Next
Exit Do: Loop
if Err/nuber <> 0 then
    Msgbox err.description
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top