Jump to content

Remove Empty Folders


tazdev
 Share

Recommended Posts

I was trying to remove some folders that had nothing in it. I came up with the bleow function. What I do is in another script I run a dir c:\*.* /s /b . I check the date of the files listed and if they are too old then I have AutoIT delete them. I came across a problem. What about the folders that are now empty. I don't want them either. I added the bottom function.

$ps is the path to search

$fp is is the full file name and path (c:\abc\123)

$sh is the search results if it is 0 then it found something if -1 then it found nothing

Anyway. You may not care but I was proud that I actually did something that I couldn't find on the forum already done

Func CheckFolderForFiles( $fp )
    $ps = $fp & "\*.*"
    $sh = FileFindFirstFile( $ps )  
    If $sh = -1 Then 
        if FileExists($fp & "\") then DirRemove( $fp )
    else
        FileClose( $sh )
    Endif
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...