Sign in to follow this  
Followers 0
meetrix

Copy File Help

30 posts in this topic

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

Share this post


Link to post
Share on other sites



i dont see the problem?, your opening a file, if the file isnt open then it will copy test.log from C into your V drive.... then exit

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

[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

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

Share this post


Link to post
Share on other sites

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.

[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

#10 ·  Posted

yes i know but i was just giving the guy props :) no need to hate hehehe

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

Share this post


Link to post
Share on other sites

#12 ·  Posted

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.


[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

#13 ·  Posted

no. I did not...

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.

Share this post


Link to post
Share on other sites

#14 ·  Posted

he probaly didnt get the message box cuz its already created

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

[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

#16 ·  Posted

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

Share this post


Link to post
Share on other sites

#17 ·  Posted

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)

Share this post


Link to post
Share on other sites

#18 ·  Posted

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)

#)

Share this post


Link to post
Share on other sites

#19 ·  Posted

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.

[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

#20 ·  Posted

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)

#)

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