Jump to content

Delete more than one file simultaneously?


lyledg
 Share

Recommended Posts

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

:idiot:

Link to comment
Share on other sites

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)

next

this is a link for some array stuff

http://www.autoitscript.com/forum/index.ph...indpost&p=45086

Edited by normeus
Link to comment
Share on other sites

I think you mean something like this: :idiot:

$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 !!!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Sorry, didn't tested it for 1 item (only multiple files). :idiot:

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,

:D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...