|
-
Nov 1st, 2000, 01:40 PM
#1
Thread Starter
Fanatic Member
Hi,
Through VB, I need to delete all subFolders under a Parent folder, whether they contain data or not. Does anyone have an example of looping through the subFolders and removing them ?
I have tried deleting the Parent folder and then using MkDir to put it back, but keep receiving error messages.
Thanks for any help !
-
Nov 1st, 2000, 02:06 PM
#2
_______
<?>
Code:
'this will kill all sub folders in C:\My Documents
Option Explicit
Sub ShowFolderList(folderspec)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 In sf
s = f1.Name
fs.Deletefolder (folderspec & "\" & s)
s = s & vbCrLf
Next
End Sub
Private Sub Image1_Click()
Call ShowFolderList("C:\my documents")
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 02:17 PM
#3
Thread Starter
Fanatic Member
Thank you for that example. That "almost" works all the way. Out of 7 subFolders, 2 are left after I get the message "70 - Permission denied".
Any suggestions ?
-
Nov 1st, 2000, 02:28 PM
#4
_______
<?>
Some of the files in the folders have attributes set to read only. You need to first pass through your folders and set the attributes to Normal...then it will work.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 02:32 PM
#5
Use Deltree.
Code:
Shell "DELTREE /Y C:\MyFolder\*.*"
-
Nov 1st, 2000, 02:37 PM
#6
Thread Starter
Fanatic Member
That wasn't the exact problem, but it made me think. I am reading scanned images from a file server and they are automatically cached on the local disk. The images for the last retrieval were still displayed on the screen, so they were in use and the cache folder(s) containing them could not be deleted.
So, I just cleared the image from the screen and all seems to be working fine.
Thanks for your help.
-
Nov 1st, 2000, 05:46 PM
#7
_______
<?>
Matthew:
For future reference, your code only deletes the contents of the folder, not the folder or sub folders beneath it if they are present and contain files.
Later,
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 08:48 PM
#8
Re: <?>
Originally posted by HeSaidJoe
Matthew:
For future reference, your code only deletes the contents of the folder, not the folder or sub folders beneath it if they are present and contain files.
Later,
Wayne
It doesn't? Because I've created a copy of a folder with subdirectories in it and it deletes everything (but the main folder, which you can use the RmDir statement).
-
Nov 1st, 2000, 09:12 PM
#9
_______
<?>
Sorry Matthew:
I tested it but not fully.
Weird, if you have a space in the folder name it doesn't recognize it and so it does nothing. If my folder is called A Wayne will do nothing but if it's AWayne then it does it's thing.
My apologies... it does kill the subs but not the parent. I originally tested it on a folder with a space in it's name and because the 3 subs remained I figured it did the parent but not the subs when in fact I must have had nothing in the parent but the 3 subs and that would account for the subs not being touched and my thinking it cleaned the parent.
Wayne

"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 1st, 2000, 09:16 PM
#10
Re: <?>
Originally posted by HeSaidJoe
Sorry Matthew:
I tested it but not fully.
Weird, if you have a space in the folder name it doesn't recognize it and so it does nothing. If my folder is called A Wayne will do nothing but if it's AWayne then it does it's thing.
My apologies... it does kill the subs but not the parent. I originally tested it on a folder with a space in it's name and because the 3 subs remained I figured it did the parent but not the subs when in fact I must have had nothing in the parent but the 3 subs and that would account for the subs not being touched and my thinking it cleaned the parent.
Wayne

Deltree...
Kill ..\*.*
RmDir MyFolder
Notice: I am always right!
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
|