jzachariasen Posted December 17, 2008 Share Posted December 17, 2008 I have this script, and it works well...$search = FileFindFirstFile("D:\SWImport\*.*") If $search = -1 Then Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileDelete("D:\SWImport\"&$file) WEnd FileClose($search)But right before FileDelete("D:\SWImport\"&$file) I need to spit the $search variable out to a txt file so I have a log of what was deleted.Does anybody have an idea about how to do this?In short, I need $search to append log.txt with its value. Log.txt will then have a list of the files that were deleted. Link to comment Share on other sites More sharing options...
Mobius Posted December 17, 2008 Share Posted December 17, 2008 (edited) Something like this? CONST $c_Log = @SCRIPTDIR &"\DEL.log" GLOBAL $h_Log, $h_Search $h_search = FileFindFirstFile("D:\SWImport\*.*") If $h_Search = -1 Then Exit $h_Log = FileOpen($c_Log,1) If $h_Log = -1 Then Exit While 1 $file = FileFindNextFile($h_Search) If @error Then ExitLoop IF FileDelete("D:\SWImport\"& $file) THEN FileWriteLine($h_Log,$file) ENDIF WEnd FileClose($h_Search) FileClose($h_Log) Ed: Bit better. Edited December 17, 2008 by Mobius Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 17, 2008 Share Posted December 17, 2008 I have this script, and it works well... $search = FileFindFirstFile("D:\SWImport\*.*") If $search = -1 Then Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileDelete("D:\SWImport\"&$file) WEnd FileClose($search) But right before FileDelete("D:\SWImport\"&$file) I need to spit the $search variable out to a txt file so I have a log of what was deleted. Does anybody have an idea about how to do this? In short, I need $search to append log.txt with its value. Log.txt will then have a list of the files that were deleted. The _FileWriteLog() UDF automatically formats with a Date/Time stamp: #include <File.au3> Global $sLogFile = @ScriptDir & "\LogFile.log" $search = FileFindFirstFile("D:\SWImport\*.*") If $search = -1 Then _FileWriteLog($sLogFile, "No files found in D:\SWImport") Exit Else _FileWriteLog($sLogFile, "File(s) found at D:\SWImport\*.*") EndIf While 1 $file = FileFindNextFile($search) If @error Then _FileWriteLog($sLogFile, "Finished deleting files.") FileClose($search) ExitLoop Else _FileWriteLog($sLogFile, "Deleting file: " & $file) FileDelete("D:\SWImport\" & $file) EndIf WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jzachariasen Posted December 17, 2008 Author Share Posted December 17, 2008 Thank you Mobius, that works great! I may have never figured that one out on my own. Link to comment Share on other sites More sharing options...
jzachariasen Posted December 18, 2008 Author Share Posted December 18, 2008 PsaltyDS, thank you for the _FileWriteLog tips. It works very well! Link to comment Share on other sites More sharing options...
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