Sign in to follow this  
Followers 0
alphawarrior2000

FileOpenDialog "File Not Found"

30 posts in this topic

#include <Array.au3>

#include <File.au3>

Dim $i, $var2, $var, $dir, $i2

$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)

If @error = 1 Then

Exit

EndIf

$var5 = FileSelectFolder("Choose Directory to Copy Files to", @DesktopDir, 1, "C:\WINDOWS\Student\Student Local")

$var6 = FileSelectFolder("Choose Directory to Copy Files to", @DesktopDir, 1, "C:\WINDOWS\Teacher\Teacher Local")

If @error = 1 Then

Exit

EndIf

$var4 = StringSplit($var3, "|", 1)

If $var4[0] > 1 Then

$dir = $var4[1]

For $i = 2 to _ArrayMax($var4)

$file = $dir & "\" & $var4[$i]

$var = FileCopy($file, $var5, 1)

$var2 = FileCopy($file, $var6, 1)

Next

ElseIf $var4[0] = 1 Then

For $i = 1 to _ArrayMax($var4)

$file = $var4[$i]

$var = FileCopy($file, $var5, 1)

$var2 = FileCopy($file, $var6, 1)

Next

EndIf

If $var2 = 1 Then

MsgBox(0, "Success", "File(s) copied to " & $var5 & " successfully")

ElseIf @error = 0 Then

Msgbox(0, "Failure", "File(s) copied to " & $var5 & " successfully")

EndIf

If $var = 1 Then

Msgbox(0, "Success", "File(s) copied to " & $var6 & " successfully")

ElseIf @error = 0 Then

Msgbox(0, "Failure", "File(s) copied to " & $var6 & " successfully")

EndIf

I cannot get multiple *.lnk files to copy. If I just select one file, it'll work like a charm, but if I select multiple files it errors out stating it cannot find the file. Please help!!

Share this post


Link to post
Share on other sites



#include <array.au3>;Only for _ArrayDisplay
;Results with multiple files are seperated by |
;We need to make an account for this
Dim $aHoldFiles[2]
$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
If @error Then
    MsgBox(64, 'Error', 'Error finding files')
ElseIf StringInStr($var3, '|') Then
    $aHoldFiles = StringSplit($var3, '|')
Else
    $aHoldFiles[1] = $var3
EndIf
_ArrayDisplay($aHoldFiles, 'Example')


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#include <array.au3>;Only for _ArrayDisplay
;Results with multiple files are seperated by |
;We need to make an account for this
Dim $aHoldFiles[2]
$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
If @error Then
    MsgBox(64, 'Error', 'Error finding files')
ElseIf StringInStr($var3, '|') Then
    $aHoldFiles = StringSplit($var3, '|')
Else
    $aHoldFiles[1] = $var3
EndIf
_ArrayDisplay($aHoldFiles, 'Example')
Even when adding the code it still will not actually copy the files themselves, it just doesn't do anything. It says it copied like it should've, but never does with multiple files. If you do just a single file then it works...

Share this post


Link to post
Share on other sites

Even when adding the code it still will not actually copy the files themselves, it just doesn't do anything. It says it copied like it should've, but never does with multiple files. If you do just a single file then it works...

It will handle the error now... but it won't copy the files. in the FileOpenDialog() add 1 + 4, and you will see what I mean.

Thanks.

Share this post


Link to post
Share on other sites

How are you trying to copy them and or what do you mean by "copy"?

It's an array now, you just can't put in the variable name:

For $iCC = 1 To UBound($aHoldFiles)
    MsgBox(64, 'Info', $aHoldFiles[$iCC]);$aHoldFile then [ then Number then ] holds the value of the file in question
    ;$aHoldFile by itself will return nothing as the file
    ;$var3 will now return the entire contents, so the file isn't a file, it's 4 of them (or how ever many you chose)
Next

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

How are you trying to copy them and or what do you mean by "copy"?

It's an array now, you just can't put in the variable name:

For $iCC = 1 To UBound($aHoldFiles)
    MsgBox(64, 'Info', $aHoldFiles[$iCC]);$aHoldFile then [ then Number then ] holds the value of the file in question
    ;$aHoldFile by itself will return nothing as the file
    ;$var3 will now return the entire contents, so the file isn't a file, it's 4 of them (or how ever many you chose)
Next
Have you not read the code? I am not asking how to copy files period, I am asking why can't I copy multiple *.LNK (shortcut) files. With this program I wrote I can copy multiple files of anything else but *.LNK files, why?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

In all fairness, you didn't mention that it worked fine with other files.

edit - clipped out my other comment. trying something.

Edited by xcal

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Have you not read the code? I am not asking how to copy files period, I am asking why can't I copy multiple *.LNK (shortcut) files. With this program I wrote I can copy multiple files of anything else but *.LNK files, why?

Don't be a dumb ass. You're asking for help, I gave you the solution, now do something with it.

Edit:

As far as "reading the code", did you bother to try the code I presented?

One thing you might have done, is "read" what I wrote.

I tried my own example I provided for you before I posted it, and it does in fact work.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

In all fairness, you didn't mention that it worked fine with other files.

edit - clipped out my other comment. trying something.

Well, I figured you guys have experience in this. Regardless, you can copy ONE *.lnk file no problem, but if you try to copy multiple *.LNK files the last file you selected says, "file not found" and errors out there. This error will only occur if you have the flag 1 enabled on FileOpenDialog. If not, then the program finishes but does not copy anything of course. *.LNK files are the only files in which I am having this issue with, I can copy multiple files at once with no problems.

Also, I can work with arrays so far just fine... if you were to look at the rest of the code you would see that.

Thanks.

Share this post


Link to post
Share on other sites

Well, I figured you guys have experience in this. Regardless, you can copy ONE *.lnk file no problem, but if you try to copy multiple *.LNK files the last file you selected says, "file not found" and errors out there. This error will only occur if you have the flag 1 enabled on FileOpenDialog. If not, then the program finishes but does not copy anything of course. *.LNK files are the only files in which I am having this issue with, I can copy multiple files at once with no problems.

Also, I can work with arrays so far just fine... if you were to look at the rest of the code you would see that.

Thanks.

Your solution sucks. It does not fix the problem I just described.

Share this post


Link to post
Share on other sites

Ok, I didn't read your code too closely, because all I wanted to see was if you could copy multiple LNK files. I tried it with the below, and it works perfectly fine... so I'd have to say the problem is with you.

$lnk = FileOpenDialog('test', @StartMenuDir, 'shortcuts (*.lnk)', 4)

$files = StringSplit($lnk, '|')

For $i = 1 To UBound($files) - 1
    FileCopy($files[$i], @DesktopDir & '\test')
Next

Share this post


Link to post
Share on other sites

Ok, I didn't read your code too closely, because all I wanted to see was if you could copy multiple LNK files. I tried it with the below, and it works perfectly fine... so I'd have to say the problem is with you.

$lnk = FileOpenDialog('test', @StartMenuDir, 'shortcuts (*.lnk)', 4)

$files = StringSplit($lnk, '|')

For $i = 1 To UBound($files) - 1
    FileCopy($files[$i], @DesktopDir & '\test')
Next
Or the problem is with the way I am handling that array. Regardless, I appreciate your help.

Share this post


Link to post
Share on other sites

Your solution sucks. It does not fix the problem I just described.

So you are a dumb ass?

The statement above is just... well it's just incorrect.

It splits the files you selected into an array... do you know what an array is? Do you know how to use an array? How did you think it would return multiple files?

If you selected 2 files, the return would be something like:

C:\Test\example.lnk|C:\Test\example2.lnk

Now, the way you are checking the files (incorrectly), it does the whole string like the above, so OF COURSE the file doesn't exist because there is no file: C:\Test\example.lnk|C:\Test\example2.lnk (Duh!)

The $HoldFile = StringSplit($var3, '|') separates the 2 files, so now:

$aHoldFile[1] = C:\Test\example.lnk

$aHoldFile[2] = C:\Test\example2.lnk

And when checking the files, you have to use the [n] to get the value.

Ok, now how does that suck?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

That still makes the problem with you. :)

Xcal, your code copies the entire directory, it doesn't handle just the files you selected. Nice try.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Here this will solve the issue of wondering whether it should be an array or not, this way it will always return an array:

#include <array.au3>
$aArray = _FileOpenDialogArray("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
_ArrayDisplay($aArray, '')

Func _FileOpenDialogArray($sTitle, $sInitDir, $sFilter, $nOptions = Default, $sDefaultName = Default)
    Local $sDialog = FileOpenDialog($sTitle, $sInitDir, $sFilter, $nOptions, $sDefaultName)
    If StringInStr($sDialog, '|') Then
        Local $aSplit = StringSplit($sDialog, '|'), $sHold = ''
        For $iCC = 2 To UBound($aSplit) - 1
            $sHold &= $aSplit[1] & '\' & $aSplit[$iCC] & Chr(1)
        Next
        Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    EndIf
    Local $aArray[2] = [1,$sDialog]
    Return $aArray
EndFunc

Edit:

Had to fix example

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Here this will solve the issue of wondering whether it should be an array or not, this way it will always return an array:

#include <array.au3>
$aArray = _FileOpenDialogArray("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
_ArrayDisplay($aArray, '')

Func _FileOpenDialogArray($sTitle, $sInitDir, $sFilter, $nOptions = Default, $sDefaultName = Default)
    Local $sDialog = FileOpenDialog($sTitle, $sInitDir, $sFilter, $nOptions, $sDefaultName)
    If StringInStr($sDialog, '|') Then
        Local $aSplit = StringSplit($sDialog, '|'), $sHold = ''
        For $iCC = 2 To UBound($aSplit) - 1
            $sHold &= $aSplit[1] & '\' & $aSplit[$iCC] & Chr(1)
        Next
        Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    EndIf
    Local $aArray[2] = [1,$sDialog]
    Return $aArray
EndFunc

Ok, Smoke_n, I love the function but add a 1 + to the flag of the FileOpenDialog, and you'll see the problem I am running into. I used just your code and the problem still exists.

I do apperciate it though, I really do.

Edit:

Had to fix example

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Revised the function just a tad, but nothing that would have effected the previous one.

#include <array.au3>
$aArray = _FileOpenDialogArray("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4 + 1)
_ArrayDisplay($aArray, '')

Func _FileOpenDialogArray($sTitle, $sInitDir, $sFilter, $nOptions = Default, $sDefaultName = '')
    Local $sDialog = FileOpenDialog($sTitle, $sInitDir, $sFilter, $nOptions, $sDefaultName)
    If @error Then Return SetError(1, 0, '')
    If StringInStr($sDialog, '|') Then
        Local $aSplit = StringSplit($sDialog, '|'), $sHold = ''
        For $iCC = 2 To UBound($aSplit) - 1
            $sHold &= $aSplit[1] & '\' & $aSplit[$iCC] & Chr(1)
        Next
        Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    EndIf
    Local $aArray[2] = [1,$sDialog]
    Return $aArray
EndFunc

This worked fine for me:

I typed:

"File One" "File Two"

In the dialog for Multiple files, and it returned the result I expected.

Then I mistyped one of them and it returned an error as it should (File could not be found).

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Xcal, your code copies the entire directory, it doesn't handle just the files you selected. Nice try.

You're right, I screwed up on what FileOpenDialog returns.

$lnk = FileOpenDialog('test', @StartMenuDir, 'shortcuts (*.lnk)', 4)

If @error Then
    MsgBox(0, '', 'no files selected')
    Exit
EndIf

$files = StringSplit($lnk, '|')

If StringInStr($lnk, '|') Then
    For $i = 2 To UBound($files) - 1
        FileCopy($files[1] & '\' & $files[$i], @DesktopDir & '\test')
    Next
Else
    FileCopy($files[1], @DesktopDir & '\test')
EndIf

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  
Followers 0