gr1fter Posted July 10, 2015 Posted July 10, 2015 #include <File.au3> $logfilename="D:\test.log" FileDelete("D:\test.log") EmptyFolder("D:\test") Func EmptyFolder($FolderToDelete) $AllFiles=_FileListToArrayRec($FolderToDelete,"*|*.log;*.txt", 0, 1, 1, 1) If IsArray($AllFiles) Then For $i = 1 To $AllFiles[0] $delete = FileDelete($FolderToDelete & "\" & $AllFiles[$i]) _FileWriteLog($logfilename,$FolderToDelete & "\" & $AllFiles[$i]& " =>"&$delete & @CRLF) Next EndIf EndFunc I am trying to delete files in a directory by exclude all log and text files. The code above is working fine for the root files, but its not using the exclusion for recursive folders, it is just deleting everything. Is there something I am missing here? I have the option set to search in all subfolders (unlimited recursion) but that doesnt appear to be working for me. Thanks,
JohnOne Posted July 10, 2015 Posted July 10, 2015 (edited) I've never really had a call to use this function, but it might be that your mask should be."*|*.log;*.txt|*"To exclude folders from being returned in the array, otherwise all folders in root array will be deleted.But I could be off on that. Edited July 10, 2015 by JohnOne Typo AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
gr1fter Posted July 10, 2015 Author Posted July 10, 2015 I'm not sure what is going on with the filter, but this is working, so I'm happy! #include <File.au3> $logfilename="D:\test.log" FileDelete("D:\test.log") EmptyFolder("D:\test") Func EmptyFolder($FolderToDelete) $AllFiles=_FileListToArrayRec($FolderToDelete,"*", 1, 1, 1, 1) If IsArray($AllFiles) Then For $i = 1 To $AllFiles[0] If StringInStr($AllFiles[$i],".txt") <> 0 Or StringInStr($AllFiles[$i],".log") <> 0 Then $delete = "skipped" _FileWriteLog($logfilename,$FolderToDelete & "\" & $AllFiles[$i]& " =>"&$delete & @CRLF) Else $delete = "deleted" _FileWriteLog($logfilename,$FolderToDelete & "\" & $AllFiles[$i]& " =>"&$delete & @CRLF) EndIf Next EndIf EndFunc
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