Jump to content
Sign in to follow this  
gr1fter

_FileListToArrayRec - exclusion issues

Recommended Posts

gr1fter
#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, 

Share this post


Link to post
Share on other sites
JohnOne

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 by JohnOne
Typo

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
gr1fter

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

 

Share this post


Link to post
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
Sign in to follow this  

×