|
-
Jul 28th, 2000, 03:47 PM
#1
Thread Starter
Lively Member
How can I delete a folder and all its contents?
rmdir only works if the folder is empty.
Is there no simlpe VB function or API call to do this task?
If so - the world is one strange place.
Thanks.
Dan.
-
Jul 28th, 2000, 03:54 PM
#2
Use the RemoveDirectory API.
Code:
Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As Long
Private Sub Command1_Click()
'Delete all files in it so it's empty
Kill "C:\MyDir\*.*"
RemoveDirectory "C:\MyDir"
End Sub
-
Jul 28th, 2000, 03:58 PM
#3
Hyperactive Member
Or you could use the filesystemobject. It will delete folder/files and all.
Code:
Dim fso
Set fso=CreateObject("scripting.filesystemobject")
fso.DeleteFolder("c:\windows\desktop\junk")
-
Jul 28th, 2000, 04:04 PM
#4
Thread Starter
Lively Member
It seems that its exactly the same as "RmDir".
if I have to remove all files in the directory before calling the function then I don't see the difference.
Is there no function that deletes an entire directory with out having to delete all the files inside it first?
Otherwise I have to go through each subdirectory and delete it too and so on ...
Thanks.
Dan.
-
Jul 28th, 2000, 04:06 PM
#5
Thread Starter
Lively Member
Thanks reeset.
My post was reffering to megatron .
(no hard feelings megatron....)
Will this work in vb5?
-
Jul 28th, 2000, 04:38 PM
#6
Hyperactive Member
sure, you just have to have the:
scrrun.dll in your system folder.
If you don't you can get it from MS.
-
Jul 28th, 2000, 04:57 PM
#7
Thread Starter
Lively Member
Thanks reeset.
Is there a filesystemobject method that checks if there are any directories at all in a current drive?
Or subdirectories in a given directory?
Thanks.
Dan.
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
|