Results 1 to 3 of 3

Thread: Search subdirectories and remove empty folders

  1. #1

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    Search subdirectories and remove empty folders

    Code:
    Private Sub CleanUp()
    
        Dim sNextDir As String
        sNextDir = Dir(strWorkDir, vbDirectory)
            While sNextDir <> ""
                If (sNextDir <> ".") And (sNextDir <> "..") Then
                    Dim sNextFile As String
                    sNextFile = Dir(strWorkDir & sNextDir & "\*.*")
                    Dim intTeller As Integer
                    While sNextFile <> ""
                        intTeller = intTeller + 1
                        sNextFile = Dir
                    Wend
                    If intTeller = 0 Then RmDir (strWorkDir & sNextDir)
                End If
                sNextDir = Dir
            Wend
    End Sub
    This code gives me Run Time Error 5 (Invalid procedure call or argument) and highlights this line
    Code:
     sNextDir = Dir
    The purpose of the code is to delete empty subfolders!
    Anyone got a clue?
    Thx allready
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  2. #2

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267
    Could it be possible that a Dir function cannot be nested?
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Yes... The Dir has problems with that... If you look in the codebank you can find other ways of doing the same thing : with FSO and APIs...


    Has someone helped you? Then you can Rate their helpful post.

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