Results 1 to 3 of 3

Thread: [RESOLVED] Get at sub folders in a special folder

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Resolved [RESOLVED] Get at sub folders in a special folder

    I am trying to get into sub folders inside a special folder (the temp folder) programmatically and I am not having a lot of success. With Microsoft Scripting Runtime added to the references, the code:
    Code:
    Sub GetTempFolder_2()
        Dim FSO As Object, TmpFolder As Object
        Dim sPath As String
        Dim ft As File
        Dim tempfiles As Files
        
        Set FSO = CreateObject("scripting.filesystemobject")
        Set TmpFolder = FSO.GetSpecialFolder(2)
        Set tempfiles = TmpFolder.Files
        sPath = TmpFolder.Path
    
    For Each ft In tempfiles
    If Right(ft.Name, 3) = "tmp" Then
    On Error Resume Next
    
    ft.Delete
    If Err.Number = 70 Then
    GoTo NextTry
    End If
    End If
    NextTry:
    Next ft
    
        On Error Resume Next
    
    End Sub
    gets me into the Temp folder but I know there are some sub folders in there, with more stale cookies in them that I want to remove & I haven’t been able to get at them.

    (The particular drive I am working on has a structure like:
    C:\Temp\IE5\Cookies
    so I actually need to go down a couple of levels.)

    Can anyone tell me how to do this?

    Thank you

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Get at sub folders in a special folder

    "I haven’t been able to get at them" -- what does that mean? Do you get an error or something?

    If you're expecting to get at them with this:
    Set tempfiles = TmpFolder.Files
    You won't... you'll only get the files... that's what .Files means... that's why you're not seeing your folder in the list...

    I'd look to see if the object in TmpFolder also has a Folders property (or it could be .Directories) ... if it does, then you should be able to get at that object, find the "Cookies" folder object in there, and from THAT object, then finally get to its .Files which will give you everything in there.

    Make sense?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Re: Get at sub folders in a special folder

    Dear tg

    Thank you for your reply. Questions always make much so much more sense to the writer than the reader!

    The following code seems to be doing the trick:

    Code:
    Sub GetTempFolder_2()
        Dim FSO As Object, TmpFolder As Object
        Dim sPath As String
        Dim ft As File
        Dim tempfiles As Files
        Dim intempfolder As Folder
        Dim innerfolds As Folders
        i = 1
        
       For j = 0 To 2
        Set FSO = CreateObject("scripting.filesystemobject")
        Set TmpFolder = FSO.GetSpecialFolder(j)
        Set tempfiles = TmpFolder.Files
        Set innerfolds = TmpFolder.SubFolders
        sPath = TmpFolder.Path
        
    Sheets(1).Cells(1 + j, 1) = TmpFolder.Name
    Sheets(1).Cells(1 + j, 2) = sPath
    Sheets(1).Cells(1 + j, 3) = "Folder no: " & j
    
        On Error Resume Next
    i = 1
    For Each intempfolder In innerfolds
    Sheets(1).Cells(1 + j, (3 * i) + 1) = intempfolder.Name
    Sheets(1).Cells(1 + j, (3 * i) + 2) = intempfolder.Path
    Sheets(1).Cells(1 + j, (3 * i) + 3) = "Folder no: " & j & ", sub-folder no: " & i
    
    i = i + 1
    Next intempfolder
    
    Next j
    
    End Sub
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width