Sign in to follow this  
Followers 0
alphawarrior2000

FileCopy won't copy!

5 posts in this topic

#include <Array.au3>

Dim $i, $var2, $var
$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
If @error = 1 Then
    Exit
EndIf
$var5 = "C:\WINDOWS\Student\Student Local\"
$var6 = "C:\WINDOWS\Teacher\Teacher Local\"
$var4 = StringSplit($var3, "|", 1)
If $var4[0] > 1 Then 
    For $i = 2 to _ArrayMax($var4)
    $sFileName = $var4[$i]
    $sPath = $var4[1]
    $sFile2Copy = $sPath & "\" & $sFileName
    $sDestination1 = $var5
    $sDestination2 = $var6
    $sFile2Des = $sDestination1 & $sFileName
    $var = FileCopy($sFile2Copy, $sFile2Des, 1)
    $var2 = FileCopy($sFile2Copy, $sFile2Des, 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 $var = 1 Then
    MsgBox(0, "Success", "File(s) copied to " & $var5 & " successfully")
ElseIf @error = 0 Then
    Msgbox(0, "Failure", "File(s) copied to " & $var5 & " unsuccessfully")
EndIf
If $var2 = 1 Then
    Msgbox(0, "Success", "File(s) copied to " & $var6 & " successfully")
ElseIf @error = 0 Then
    Msgbox(0, "Failure", "File(s) copied to " & $var6 & " unsuccessfully")
EndIf

FileCopy returns a 0, even though all my viarables and file handling is correct.

Any ideas? :)

Share this post


Link to post
Share on other sites



FileCopy returns a 0, even though all my viarables and file handling is correct.

Any ideas? :)

It could be the folders C:\WINDOWS\Student\Student Local\ and C:\WINDOWS\Teacher\Teacher Local\ not exists. To fix this issue I change FileCopy() flag value from 1 to 9. This way if the folders not exits it will be created. After this fix your script run fine for single selection, once I try multi selection it won't copy to C:\WINDOWS\Teacher\Teacher Local\ folder. You are using the same destination folder for both FileCopy() "$sFile2Des = $sDestination1 & $sFileName".

give it a try.

;#include <Array.au3>

Dim $i, $var2, $var
$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
If @error = 1 Then
    Exit
EndIf
$var5 = "C:\WINDOWS\Student\Student Local\"
$var6 = "C:\WINDOWS\Teacher\Teacher Local\"
$var4 = StringSplit($var3, "|", 1)

If $var4[0] > 1 Then
    For $i = 2 To $var4[0] ;_ArrayMax($var4)
        $sFileName = $var4[$i]
        $sPath = $var4[1]
        $sFile2Copy = $sPath & "\" & $sFileName
        $sDestination1 = $var5 & $sFileName
        $sDestination2 = $var6 & $sFileName
        
        $var = FileCopy($sFile2Copy, $sDestination1, 9)
        $var2 = FileCopy($sFile2Copy, $sDestination2, 9)
    Next
ElseIf $var4[0] = 1 Then
    For $i = 1 To $var4[0]  ;_ArrayMax($var4)
        $file = $var4[$i]
        $var = FileCopy($file, $var5, 9)
        $var2 = FileCopy($file, $var6, 9)
    Next
EndIf

If $var = 1 Then
    MsgBox(0, "Success", "File(s) copied to " & $var5 & " successfully")
ElseIf @error = 0 Then
    MsgBox(0, "Failure", "File(s) copied to " & $var5 & " unsuccessfully")
EndIf
If $var2 = 1 Then
    MsgBox(0, "Success", "File(s) copied to " & $var6 & " successfully")
ElseIf @error = 0 Then
    MsgBox(0, "Failure", "File(s) copied to " & $var6 & " unsuccessfully")
EndIf

Note:

I will change the following lines:

$var5 = "C:\WINDOWS\Student\Student Local\"

$var6 = "C:\WINDOWS\Teacher\Teacher Local\"

for

$var5 = @WindowsDir & "\Student\Student Local\"

$var6 = @WindowsDir & "\Teacher\Teacher Local\"

This way you don't have to worry if is C:\Windows, C:\Winnt or where the user called when install windows.

If this still not working for you I will check if the user is part of Administrator group. Don't forget you are trying to copy into C:\Windows and if this is for a school usually user don't have adminatrator right.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

It could be the folders C:\WINDOWS\Student\Student Local\ and C:\WINDOWS\Teacher\Teacher Local\ not exists. To fix this issue I change FileCopy() flag value from 1 to 9. This way if the folders not exits it will be created. After this fix your script run fine for single selection, once I try multi selection it won't copy to C:\WINDOWS\Teacher\Teacher Local\ folder. You are using the same destination folder for both FileCopy() "$sFile2Des = $sDestination1 & $sFileName".

give it a try.

;#include <Array.au3>

Dim $i, $var2, $var
$var3 = FileOpenDialog("Choose file(s)", @MyDocumentsDir, "All (*.LNK)", 4)
If @error = 1 Then
    Exit
EndIf
$var5 = "C:\WINDOWS\Student\Student Local\"
$var6 = "C:\WINDOWS\Teacher\Teacher Local\"
$var4 = StringSplit($var3, "|", 1)

If $var4[0] > 1 Then
    For $i = 2 To $var4[0] ;_ArrayMax($var4)
        $sFileName = $var4[$i]
        $sPath = $var4[1]
        $sFile2Copy = $sPath & "\" & $sFileName
        $sDestination1 = $var5 & $sFileName
        $sDestination2 = $var6 & $sFileName
        
        $var = FileCopy($sFile2Copy, $sDestination1, 9)
        $var2 = FileCopy($sFile2Copy, $sDestination2, 9)
    Next
ElseIf $var4[0] = 1 Then
    For $i = 1 To $var4[0]  ;_ArrayMax($var4)
        $file = $var4[$i]
        $var = FileCopy($file, $var5, 9)
        $var2 = FileCopy($file, $var6, 9)
    Next
EndIf

If $var = 1 Then
    MsgBox(0, "Success", "File(s) copied to " & $var5 & " successfully")
ElseIf @error = 0 Then
    MsgBox(0, "Failure", "File(s) copied to " & $var5 & " unsuccessfully")
EndIf
If $var2 = 1 Then
    MsgBox(0, "Success", "File(s) copied to " & $var6 & " successfully")
ElseIf @error = 0 Then
    MsgBox(0, "Failure", "File(s) copied to " & $var6 & " unsuccessfully")
EndIf

Note:

I will change the following lines:

$var5 = "C:\WINDOWS\Student\Student Local\"

$var6 = "C:\WINDOWS\Teacher\Teacher Local\"

for

$var5 = @WindowsDir & "\Student\Student Local\"

$var6 = @WindowsDir & "\Teacher\Teacher Local\"

This way you don't have to worry if is C:\Windows, C:\Winnt or where the user called when install windows.

If this still not working for you I will check if the user is part of Administrator group. Don't forget you are trying to copy into C:\Windows and if this is for a school usually user don't have adminatrator right.

Well, I fixed all the issues you spoke of, and it still fails when trying to do it with multiple files as well. I am the administrator and a local admin, but will program recognize that automatically or do I have to tell it that?

Share this post


Link to post
Share on other sites

Well, I fixed all the issues you spoke of, and it still fails when trying to do it with multiple files as well. I am the administrator and a local admin, but will program recognize that automatically or do I have to tell it that?

Did you copy and past the code on post #2? it should work, at list is working on my computer.

I will add this line at the beging of the script to be sure that your account is part of administrator group

If Not IsAdmin() Then 
    MsgBox(0, 'Admin', @UserName & ' is not part of administrator group.')
    Exit
EndIfoÝ÷ Ø   ÝûaË-Yg¢Ü(®H§;¬µ«µë-#¥Úò¶(§(§¶azצ¥ú%uêÌk+azènW¦Ëajܨ¹Ú'ßÛaj÷«m~ÂÓÝ°whÂÇè׫jëh×6$var5 = @TempDir & "\Student\Student Local\"
$var6 = @TempDir & "\Teacher\Teacher Local\"

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Did you copy and past the code on post #2? it should work, at list is working on my computer.

I will add this line at the beging of the script to be sure that your account is part of administrator group

If Not IsAdmin() Then 
    MsgBox(0, 'Admin', @UserName & ' is not part of administrator group.')
    Exit
EndIfoÝ÷ Ø   ÝûaË-Yg¢Ü(®H§;¬µ«µë-#¥Úò¶(§(§¶azצ¥ú%uêÌk+azènW¦Ëajܨ¹Ú'ßÛaj÷«m~ÂÓÝ°whÂÇè׫jëh×6$var5 = @TempDir & "\Student\Student Local\"
$var6 = @TempDir & "\Teacher\Teacher Local\"
I copied and pasted everything so far you have suggested sir, and it still is not successful... I apperciate the help, is there anything else to try?

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