Jump to content

FileCopy Succeeded but returns 0


Keithw
 Share

Recommended Posts

Hey folks, I am using the FileCopy command, which does what I want, but the function returns 0.  The funny thing is that it was returning 1 yesterday.  I reverted my changes, but it still returns 0         :(

 

Local $bCopyCheck = FileCopy($sComputerDir & $sAdobeFolder, @ScriptDir, $FC_OVERWRITE)
            If ($bCopyCheck = 0) Then
                GUICtrlSetData($Tab2OutputLabel, "Failed to Copy Key File")
                MsgBox(0,"Test", "FileCopy Func Returned " & $bCopyCheck)
                Return
            Else
                GUICtrlSetData($Tab2OutputLabel, "So far so good!")
                FileChangeDir(@ScriptDir)
                Local $bFHandle = FileOpen("*.swi")

 

Edited by Keithw
Link to comment
Share on other sites

  • Developers

Well, when a 0 is returned it will not have been fully successful. 
There is not enough information to really be able to help you.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Well, I added a check to see the value of @error and @extended macro's and recompiled and now the function is returning 1....

 

Well, when a 0 is returned it will not have been fully successful. 
There is not enough information to really be able to help you.

Jos

Regardless if the function returns 1 or 0 it copies the file over. :|

Link to comment
Share on other sites

  • Developers

I could be copying a couple of files and then hitting an issue and failing, hence my comment of "not enough info".

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Well, I won't beat a dead horse.  One more question(I know you answer a lot of them here  ^_^).  After the file is copied, I need to open it with FileOpen()(which is returning -1).  The name of the file is not foreknown so I'm using the file extension:

GUICtrlSetData($Tab2OutputLabel, "So far so good!")
                FileChangeDir(@ScriptDir)
                Local $bFHandle = FileOpen("*.swi")
                If $bFHandle = -1 Then
                    GUICtrlSetData($Tab2OutputLabel,"Unable to open key file")
                    Return
                Else
                    GUICtrlSetData($Tab2OutputLabel, "Keyfile Opened!")
                EndIf

The full file extension is ".swidtag".  I'm not sure if I'm using the wildcard correctly from the example above, but I think this should be searching for any files in the current active directory with ".swi" in its extension.  I saw StringRegExp() but I'm not sure how to get a list of file names in a directory so I could sort through an array with this built-in function.

 

 

Link to comment
Share on other sites

  • Developers

Well, I won't beat a dead horse.  

I would keep on beating till it works properly and returning a 1 as you have no means to check success now. ;)

One more question(I know you answer a lot of them here  ^_^).  After the file is copied, I need to open it with FileOpen()(which is returning -1).  The name of the file is not foreknown so I'm using the file extension:

The full file extension is ".swidtag".  I'm not sure if I'm using the wildcard correctly from the example above, but I think this should be searching for any files in the current active directory with ".swi" in its extension. 

You obviously can't open a filename with a wildcard, so need to use FileFindFirstFile/FileFindNextFile to retrieve the full filename first after which you can open it.

Jos

 

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I would keep on beating till it works properly and returning a 1 as you have no means to check success now. ;)

You obviously can't open a filename with a wildcard, so need to use FileFindFirstFile/FileFindNextFile to retrieve the full filename first after which you can open it.

Jos

 

 

Then why does it say that wildcards are accepted? :blink:     FileCopy

Link to comment
Share on other sites

  • Developers

That statement was about FileOpen(), not FileCopy!

Jos

 

To re-iterate:

Your FileCopy() likely returns 0 because one of the files that qualifies your provoded filemask is unable to be copied!
You FileOpen needs the exact filename which can be retrieved with FileFindFirstFile/FileFindNextFile.

All Clear? 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That statement was about FileOpen(), not FileCopy!

Jos

 

To re-iterate:

Your FileCopy() likely returns 0 because one of the files that qualifies your provoded filemask is unable to be copied!
You FileOpen needs the exact filename which can be retrieved with FileFindFirstFile/FileFindNextFile.

All Clear? 

Okay, well I got it working with FileFind.  So now my script works all fine.  There is only 1 file in the directory I'm copying from and I've made sure there are no hidden files in that folder as well.  I am copying this file through the network, so what I do believe is happening is that another program is accessing this file during my FileCopy and for some weird reason FileCopy copies the file but returns failed.  Thanks for all your responses.

 

Local $sFileName = ""
    $sFileName = FileFindNextFile($hSearch)
    ;MsgBox(0, "", "File: " & $sFileName)
    ;Close the search handle
    FileClose($hSearch)
    Local $bFHandle = FileOpen($sFileName)
    If $bFHandle = -1 Then
        GUICtrlSetData($Tab2OutputLabel,"Unable to open key file")
        MsgBox(0,"Error","FileOpen(): " & $bFHandle & @CRLF & "@Error: " & @CRLF & @error & @CRLF & "Extended: " & @extended)
    Return

 

Edited by Keithw
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...