tazdev Posted February 17, 2005 Posted February 17, 2005 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
Valik Posted February 17, 2005 Posted February 17, 2005 What happens when you have a file without an extension in a folder? What happens to the folder then? (That's a hint that your code is flawed unless FileFindFirstFile works differently than I remember).
CyberSlug Posted February 17, 2005 Posted February 17, 2005 DirGetSize might work as an alternative method Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
tazdev Posted February 17, 2005 Author Posted February 17, 2005 Haven't tried DirGetSize. I will look into that. Even if a file has no extension it will still show up with *.* as a wildcard therefore the error code will be 0 not -1.
tazdev Posted February 17, 2005 Author Posted February 17, 2005 LOL DirGetSize would work sooooo much better reduced to only 2 lines of code. HAHAHAHAHA Thanks. $size = DirGetSize( $fp ) if $size = 0 then DirRemove( $fp )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now