Jump to content

Copy File Help


Recommended Posts

I have this simple script that should work, but it's not.. it's the little things that kill.

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK

If $file = -1 Then

FileCopy("c:\test.log", "v:\123456789.log",1)

Exit

EndIf

FileClose($file)

Let me know.. Thank you in advance for all your help

Me

Link to comment
Share on other sites

Well, that's what I thought, but for some wierd reason, when I open the V:\123456789.log file it's empty. I don't understand.

Any other thoughts?

I have this simple script that should work, but it's not.. it's the little things that kill.

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK

If $file = -1 Then

FileCopy("c:\test.log", "v:\123456789.log",1)

Exit

EndIf

FileClose($file)

Let me know.. Thank you in advance for all your help

Me

Link to comment
Share on other sites

Ok

1. Make sure all cases are the Same or else its not going to copy correctly.

2. Make sure your using the correct paramater on the FileCopy

0 = (default) do not overwrite existing files
 1 = overwrite existing files
 8 = Create destination directory structure if it doesn't exist (See Remarks).
 9 = Create destination and Overwrite existing File

If that doesnt work then , a work around would be doing a Fileread, and then do a _filecreate and then a filewrite.

Edited by thatsgreat2345
Link to comment
Share on other sites

Well, that's what I thought, but for some wierd reason, when I open the V:\123456789.log file it's empty. I don't understand.

Any other thoughts?

Is 123456789.log or test.log empty before you run the run the script? And you might want to test the result of the FileCopy() because you only do it if the FileOpen() fails, so things are going wrong already:

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then MsgBox(16, "Debug", "Error on file copy!")
    Exit
EndIf

FileClose($file)

Hope that helps... :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

no he had it right if it didnt open then he wanted it to copy thats exactly the point of the -1

That doesn't make much sense. If it failed it's probably in use, which means you would have to use FileMove() / Rename, I would imagine. Edited by SmOke_N

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.

Link to comment
Share on other sites

  • Moderators

if it failed it could mean it wasnt there :) thus he would do a filecopy

Well if that's the case, I would think that If Not FileExists() Then would be a better alternative.

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.

Link to comment
Share on other sites

I just tried your suggestion, but it did not work. ?????

:)

Is 123456789.log or test.log empty before you run the run the script? And you might want to test the result of the FileCopy() because you only do it if the FileOpen() fails, so things are going wrong already:

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then MsgBox(16, "Debug", "Error on file copy!")
    Exit
EndIf

FileClose($file)

Hope that helps... :(

Link to comment
Share on other sites

  • Moderators

Did you get the msgbox?

Why don't you explain what you actually want to do, maybe we have an easier way of doing it.

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.

Link to comment
Share on other sites

  • Moderators

no. I did not...

Try this and tell us what message box you got, and you still need to tell us what you are actually trying to do:
$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then 
        MsgBox(16, "Debug", "Error on file copy!")
    Else
        MsgBox(64, 'Info:', 'File Copied')
    Exit
Else
    MsgBox(64, 'Opened', 'The File opened')
EndIf

FileClose($file)
You will get a MsgBox().

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.

Link to comment
Share on other sites

The purpose of this script is:

There is a customer application that creates a log file on the C: drive. I want to create a log file on the Server and copy the results file from drive C: to (for Example, drive V:). Then print, but this step is already taken care off thanks to the autoit support group.

I received the following error message.

C:\Program Files\AutoIt3\Examples\Helpfile\FileCopy.au3(10,1) : ERROR: missing EndIf.

Else

^

C:\Program Files\AutoIt3\Examples\Helpfile\FileCopy.au3(5,64) : REF: missing EndIf.

If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Examples\Helpfile\FileCopy.au3 - 1 error(s), 0 warning(s)

When I add EndIF at the end and run the script. I receive the Msg "The File Opened".

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK

If $file = -1 Then

If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then

MsgBox(16, "Debug", "Error on file copy!")

Else

MsgBox(64, 'Info:', 'File Copied')

Exit

EndIf

Else

MsgBox(64, 'Opened', 'The File opened')

EndIf

FileClose($file)

Try this and tell us what message box you got, and you still need to tell us what you are actually trying to do:

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then 
        MsgBox(16, "Debug", "Error on file copy!")
    Else
        MsgBox(64, 'Info:', 'File Copied')
    Exit
Else
    MsgBox(64, 'Opened', 'The File opened')
EndIf

FileClose($file)
You will get a MsgBox().
Link to comment
Share on other sites

nice try smoke u forgot an endif :), jeesh just cleaning up your mistakes tonight, first the guictrlsetdata and now this ahhaha

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then
        MsgBox(16, "Debug", "Error on file copy!")
    Else
        MsgBox(64, 'Info:', 'File Copied')
    Exit
EndIf
Else
    MsgBox(64, 'Opened', 'The File opened')
EndIf

FileClose($file)
Link to comment
Share on other sites

Tiny mistake on SmOke_N's part:

Exit should be EndIf.

Corrected:

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then
        MsgBox(16, "Debug", "Error on file copy!")
    Else
        MsgBox(64, 'Info:', 'File Copied')
    EndIf
Else
    MsgBox(64, 'Opened', 'The File opened')
EndIf

FileClose($file)

#)

Link to comment
Share on other sites

  • Moderators

Tiny mistake on SmOke_N's part:

Exit should be EndIf.

Corrected:

#)

Thanks, that's what I get for typing in the Fast Reply window lol.

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.

Link to comment
Share on other sites

This is the error I get:

C:\Program Files\AutoIt3\Examples\Helpfile\FileCopy.au3(1,6) : ERROR: syntax error

file =

~~~~~^

C:\Program Files\AutoIt3\Examples\Helpfile\FileCopy.au3 - 1 error(s), 0 warning(s)

Tiny mistake on SmOke_N's part:

Exit should be EndIf.

Corrected:

$file = FileOpen("v:\123456789.log", 1)

; Check if file opened for reading OK
If $file = -1 Then
    If Not FileCopy("c:\test.log", "v:\123456789.log", 1) Then
        MsgBox(16, "Debug", "Error on file copy!")
    Else
        MsgBox(64, 'Info:', 'File Copied')
    EndIf
Else
    MsgBox(64, 'Opened', 'The File opened')
EndIf

FileClose($file)

#)

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...