Jump to content
Sign in to follow this  

Inconsistencies between FileDelete and FileRecycle

Recommended Posts



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?


#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.")
MsgBox(4096,"","All files created")

;-----------Loop to test FileDelete---------------------------------
$i = 1
    $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)
    $i = $i +1
Until $i = 13
MsgBox(4096, "", "End")

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.