Jump to content

_FileListToArrayRec - exclusion issues


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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