Jump to content

Delete tree


 Share

Recommended Posts

I have this script that deletes files by extension and size but I wan't It to reach all the way through and into sub directories as well, is there a function Im missing here?

_Clean()

Func _Clean()
    FileDelete("C:\ProgramData\" & @UserName & "\*.exe")
    FileDelete("C:\ProgramData\" & @UserName & "\*.au3")
    FileDelete("C:\ProgramData\" & @UserName & "\*.bat")
    FileDelete("C:\ProgramData\" & @UserName & "\*.com")
    FileDelete("C:\ProgramData\" & @UserName & "\*.ini")
    FileChangeDir("C:\ProgramData\" & @Username)
    $search = FileFindFirstFile("*.*")
While 1
    $file = FileFindNextFile($search)
    $size = FileGetSize($file) / 1048576
If @error Then ExitLoop
If $size < 1 Then
ContinueLoop
Else
    FileDelete($file)
    EndIf
WEnd
FileClose($search)
EndFunc

Edit: deleting the sub directories would be nice too :x

Edited by xJSLRx
Link to comment
Share on other sites

I wan't It to reach all the way through and into sub directories as well, is there a function Im missing here?

In a way you are. You need to use FileFindNextFile() for this to.

1) FileFindNextFile: @extended set to 1 if filename is a directory.

2) Look in Melba's signature. (RecFileListToArray)

3) search forum for some additional topics on folder recursion.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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...