Jump to content

FileCopy Bug??


Recommended Posts

Using Beta..

In order to do regression testing between V3 and Beta, I simply copy the appropriate autoIt3.exe into my Program Files Directory.

I decided to automate this swap with 2 .au3 scripts. In the PF/AutoIT directory

I added AutoIT3.V3 and AutoIT.Beta which were renamed copies of the 2 exe's.

As I would do with Explorer, I create a Second Copy of the appropriate file which I then rename using MoveFile.

Script to To use the released V3 therefore:

FileCopy ( "C:\Program Files\AutoIt3\AutoIt3.Rel", "C:\Program Files\AutoIt3\AutoIt3.Rel" , 1 ); Create Copy of AutoIT3.rel

FileMove ("C:\Program Files\AutoIt3\Copy of AutoIt3.Rel", "C:\Program Files\AutoIt3\AutoIt3.exe" , 1 ); Rename the file to .exe

I never get to the move.. the FileCopy deletes the AutoIt3.Rel file.

Perhaps it should not work..but it sure should not erase my source.

When I create a dummy Copy of AutoIt3.Rel the FileMove fails (Returns 0)

I realize now that since the Exe itself is active that the rename should fail but the Copy should work...

Back to my old .bat files!

Link to comment
Share on other sites

You do realize you're trying to copy a file onto itself, right? The results of the same source and destination in a FileCopy operation is likely undefined. FileCopy is not like the Windows shell copy which automatically prepends "Copy of" to the file.

Edit: Come to think of it, it's probably not undefined. I bet when FileCopy is told to overwrite the destination, an implicit deletion operation occurs. However, in your case, since you have the same source and destination, you've just implicitly deleted your source.

Edited by Valik
Link to comment
Share on other sites

Yes, I think you are right on.. if I change to option 0 it does not overwrite and hence no delete. I also found by testing that its not like the shell. So we agree there is no bug and that FileCopy FileA FileB works fine and FileMove FileA FileB

in same directory will rename FileA to FileB .

Link to comment
Share on other sites

The fact that insist that you think to have right is even more annoying.

What is the meaning of copy a file on itself?

You maybe mean that:

FileCopy ( "C:\Program Files\AutoIt3\AutoIt3.Rel", "C:\Program Files\AutoIt3\Copy of AutoIt3.Rel" , 1 );Create Copy of AutoIT3.rel
FileMove ("C:\Program Files\AutoIt3\Copy of AutoIt3.Rel", "C:\Program Files\AutoIt3\AutoIt3.exe" , 1 );Rename the file to .exe
Edited by ezzetabi
Link to comment
Share on other sites

Yup..but I thought it would act like the Shell and it doesn't so I needed to change it to what you have. Thanks to both of you.

PS: I know you guys know that a FILEMOVE to the same directory is a RENAME but I don't think its blazingly obvious to your average user. How about adding FILE-RENAME to the Help document showing people how to do it. I still don't know if I need to specify the overwrite flag and if I do and then don't what will happen.

Link to comment
Share on other sites

If you attempt to rename fileA to fileB, but fileB already exists, then it will fail unless you have the overwrite flag. Don't think of it as a rename (Because technically, it's not). Think of it as moving from one location to another (Totally forget that the two files are in the same directory).

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...