Sign in to follow this  
Followers 0
suroit

Inconsistencies between FileDelete and FileRecycle

1 post in this topic

Hi,

I am trying to delete large numbers of files with specific names that I can calculate. I would like to use FileRecycle with the script below, but only FileDelete seems to give me the correct return values.

When I use FileDelete, I get the predicted return values: 0 when the file doesn't exist, and 1 when the file exists. With FileRecycle, though, the return value is always 1!

Can anyone let me know if I am using this function correctly?

Thanks.

#Include <File.au3>  ; Statement required by _FileListtoArray
#include <Date.au3>
;-------------Script works as is when using FileDelete, not FileRecycle.
;           
Local $i
Local $k
Local $file
$lgName = "log.txt"
$fpath = InputBox("Delete some files", "Enter folder path","D:\_test2") & "\"
Msgbox("", "Folder path is ", $fpath)
$logfile = FileOpen($fpath & $lgName, 1)
$log = "Time: " & @hour & ":" & @min & ":" & @sec & "  Starting FileRecycle_test" & @CRLF
FileWriteLine($logfile, $log)

;---------Create test files in directory----------------------------
For $k = 5 to 10
    $txtfile = FileOpen($fpath & $k & ".txt", 1)
    If $txtfile = -1 Then  ; Check if file opened for writing OK
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    FileClose($txtfile)
Next
MsgBox(4096,"","All files created")

;-----------Loop to test FileDelete---------------------------------
$i = 1
Do  
    $FileSearch = FileFindFirstFile($fpath & $i & "*.txt")
    $file = FileFindNextFile($FileSearch)
    $RecycleSearch = FileRecycle($fpath & $i & "*.txt") 
    $log = $i & ", " & "File: " & $fpath & $i & "*.txt" & ", FileSearch= " &  $FileSearch & ", File= " & $file & ", RecycleSearch= " & $RecycleSearch
    MsgBox(4096,"", $log,1 )
    FileWriteLine($logfile, $log)
    FileClose($FileSearch)
    $i = $i +1
Until $i = 13
FileClose($logfile)
MsgBox(4096, "", "End")
Exit

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  
Followers 0