lyledg Posted December 7, 2004 Posted December 7, 2004 Gusy I want to delete multiple files that are selected through a "FileOpenDialog" The code I have thus far is: GLOBAL $Yes = 6 GLOBAL $No = 7 $logfileopen = FileOpenDialog($Message, @ScriptDir & "\Logs","All (*.log)", 1 + 4) If @error Then return Else $Answer = MsgBox(262180, "Delete?", "Do you want to continue?") If $Answer = $Yes then $logfileopen = StringReplace($logfileopen, "|", @CRLF) FileDelete($logfileopen) Return Else If $Answer = $No Then Return Endif Endif This code only delete's a single file at a time, how would I make it delete the selected files simultaneously? Meaning more than just one file at a time.. Cheers
normeus Posted December 7, 2004 Posted December 7, 2004 (edited) FileDelete can handle "*.log" but it expects a file Path ; remember to dim and all that nice stuff ; search for array on the forum ; dont delete unless you know what you are doing ( test the code first) $array = StringSplit($logfileopen, "|") for i = 1 to $array[0] FileDelete($array) nextthis is a link for some array stuffhttp://www.autoitscript.com/forum/index.ph...indpost&p=45086 Edited December 7, 2004 by normeus http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe
lyledg Posted December 7, 2004 Author Posted December 7, 2004 Mate Thanks for the code, but I cannot seem to get it working? $array = StringSplit($logfileopen, "|") for $i = 1 to $array[0] FileDelete($array) next Could you give a better example? Cheers
DaLiMan Posted December 7, 2004 Posted December 7, 2004 I think you mean something like this: $message = "Delete selected files" $var = FileOpenDialog($message, "C:\MyFolder", "All Files (*.*)", 5 ) $array = StringSplit($var, "|") for $x = 2 to $array[0] $folder = $array[1] $Del = $folder & "\" & $array[$x] FileDelete($del) next Worked at my place !!!
lyledg Posted December 7, 2004 Author Posted December 7, 2004 Mate.. This code works great, thanks ever so much, but what about if I wanted to delete a single file only. As I have tested your code, the file(s) only get deleted if you delete two files or more. Basically, I want to give the user the option to delete one or more files by holding down the CTRL button on the keyboard, selecting various files and deleting them from the Opendialog box? I guess there only has to be a small change to your code right?
DaLiMan Posted December 7, 2004 Posted December 7, 2004 Sorry, didn't tested it for 1 item (only multiple files). This should fix the problem. $message = "Delete selected files" $var = FileOpenDialog($message, "C:\MyFolder", "All Files (*.*)", 5 ) ; Check for [Cancel] in FileOpenDialog If $var = 1 Then Exit EndIf ; Script wich accually deletes the files $varchk = StringInStr($var, "|") If $varchk > 0 Then $array = StringSplit($var, "|") for $x = 2 to $array[0] $folder = $array[1] $Del = $folder & "\" & $array[$x] FileDelete($del) next ElseIf $varchk = 0 Then $Del = $var FileDelete($del) EndIf Enjoy,
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