Results 1 to 7 of 7

Thread: deleting a folder

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    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.

  2. #2
    Guest
    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

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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")

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    Thanks reeset.
    My post was reffering to megatron .
    (no hard feelings megatron....)
    Will this work in vb5?

  6. #6
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    sure, you just have to have the:
    scrrun.dll in your system folder.
    If you don't you can get it from MS.


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    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
  •  



Click Here to Expand Forum to Full Width