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.
Printable View
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.
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
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")
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.
Thanks reeset.
My post was reffering to megatron .
(no hard feelings megatron....)
Will this work in vb5?
sure, you just have to have the:
scrrun.dll in your system folder.
If you don't you can get it from MS.
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.