Nunos Posted December 11, 2013 Share Posted December 11, 2013 I am trying to write a script that will find all of the .xml files in a specific folder and then delete them without performing any tasks on any other files or folders in the directory. Below is what I tried but I am not getting it to delete them. Thank you in advance for your time. #include <File.au3> #include <Array.au3> Local $Folder = "C:\Afolder" Local $sFilter = "*.xml" Local $FileList = _FileListToArray($Folder,$sFilter) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf For $i = 0 to UBound($FileList) -1 FileDelete($FileList[$i]) Next Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 Nunos, Added some diag msg's and ran it like this... #include <File.au3> #include <Array.au3> Local $Folder = @scriptdir ;Local $Folder = "C:\Afolder" Local $sFilter = "*.xml" Local $FileList = _FileListToArray($Folder,$sFilter) if not isarray($FileList) then MsgBox(0, "", "No Files Found.") Exit EndIf If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf For $i = 0 to UBound($FileList) -1 if FileDelete($FileList[$i]) = 1 then ConsoleWrite('Deleted file = ' & $FileList[$i] & @LF) Else ConsoleWrite('Delete Failed for file = ' & $FileList[$i] & @LF) endif Next I suspect that you are not finding any files in the Dir that you are referencing. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Kidney Posted December 11, 2013 Share Posted December 11, 2013 is there a reason why you cant use the example in the help file?? it looks like it will accomplish the same thing... FileDelete("D:\*.tmp") Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 Nunos, Added some diag msg's and ran it like this... #include <File.au3> #include <Array.au3> Local $Folder = @scriptdir ;Local $Folder = "C:\Afolder" Local $sFilter = "*.xml" Local $FileList = _FileListToArray($Folder,$sFilter) if not isarray($FileList) then MsgBox(0, "", "No Files Found.") Exit EndIf If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf For $i = 0 to UBound($FileList) -1 if FileDelete($FileList[$i]) = 1 then ConsoleWrite('Deleted file = ' & $FileList[$i] & @LF) Else ConsoleWrite('Delete Failed for file = ' & $FileList[$i] & @LF) endif Next I suspect that you are not finding any files in the Dir that you are referencing. kylomas Thank you for your time and assistance with this kylomas, The files do exist in the directory but it is still not deleting them. I am not sure where it is hanging up because none of the @errors are tripping it that were added in the version you posted above. Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 You did not say it was "hanging". Are you getting any console output? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 The console returns AutoIT3.exe ended.rc:0 >Exit code: 0 Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 Nunos, Run this and post the entire console log #include <File.au3> #include <Array.au3> Local $Folder = @scriptdir ;Local $Folder = "C:\Afolder" Local $sFilter = "*.xml" Local $FileList = _FileListToArray($Folder,$sFilter) if isarray($FileList) then ConsoleWrite('Number of files returned = ' & $FileList[0] & @LF) if not isarray($FileList) then MsgBox(0, "", "No Files Found.") Exit EndIf If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf For $i = 1 to UBound($FileList) -1 ; offset 0 has the file count if FileDelete($FileList[$i]) = 1 then ConsoleWrite('Deleted file = ' & $FileList[$i] & @LF) Else ConsoleWrite('Delete Failed for file = ' & $FileList[$i] & @LF) endif Next Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 Do you want me to change the folder to the one that has the files I want to delete? Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 Yes, please... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:UsersMEDesktopScirptingAutoITIn Progress and ResearchingDelete XML.au3" /autoit3dir "C:Program FilesAutoIt3" /UserParams +>23:15:31 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0409 Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X86) >Running AU3Check (1.54.22.0) from:C:Program FilesAutoIt3 +>23:15:31 AU3Check ended.rc:0 >Running:(3.3.8.1):C:Program FilesAutoIt3autoit3.exe "C:UsersMEDesktopScirptingAutoITIn Progress and ResearchingDelete XML.au3" Number of files returned = 3 Delete Failed for file = 1 - Copy (2).xml Delete Failed for file = 1 - Copy.xml Delete Failed for file = 1.xml +>23:15:32 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 3.727 Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 (edited) Your code is running correctly (assuming that there are three files in the folder you pointed to). You might try checking file attributes and folder permissions. edit: and if these files are in use Edited December 11, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 Read Only could that be what is preventing me from deleting them? If so do you know of a way to delete them anyways? Link to comment Share on other sites More sharing options...
Solution czardas Posted December 11, 2013 Solution Share Posted December 11, 2013 You need to add the path to the folder to locate the files. FileDelete($Folder & "\" & $FileList[$i]) operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
kylomas Posted December 11, 2013 Share Posted December 11, 2013 (edited) Nunos, Add the path as czardas pointed out...apologies, completely missed that (gotcha for running everything from the same folder) Edited December 11, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Nunos Posted December 11, 2013 Author Share Posted December 11, 2013 (edited) You need to add the path to the folder to locate the files. FileDelete($Folder & "\" & $FileList[$i]) Thank you czardas and kylomas this seems to have fixed my problem. I guess I didn't understand that I wasn't deleting the items from the array but needed to reference the path first? I am still trying to learn all of the ins and outs. Thank you both again for all of your time and help. Edited December 11, 2013 by Nunos czardas 1 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