|
-
Feb 1st, 2012, 08:36 AM
#1
Thread Starter
Addicted Member
[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
-
Feb 1st, 2012, 09:20 AM
#2
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
-
Feb 2nd, 2012, 08:05 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|