Jump to content

How to use FileCopy() to create a new filename?


Go to solution Solved by water,

Recommended Posts

Posted

Hi!

I'd like to use FileCopy() to copy a file to a given directory, except that if a file with that name already exists in the output folder, I want it to create a new filename (i.e., I do NOT want to overwrite the existing file), but I can't find an already existing function to do that.

It's easy to check if the filename already exists and to devise a non-conflicting filename, but since FileCopy() does not allow you to pass it a new filename, that function obviously won't do what I want.

Is there any other existing function that allows you to specify a different output filename, or do I have to copy the file manually (i.e., with FileRead()/FileWrite() functions)?

Thanks

  • Solution
Posted

That's a bug in the help file. You can copy and rename the file in one go.

$iResult = FileCopy(@ScriptDir & "\" & @Scriptname, @ScriptDir & "\test.xyz")
MsgBox(0, "Result", $iResult)

Copies the script file file with a new name. MsgBox displays "1" if successful.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 1/27/2014 at 8:52 AM, water said:

That's a bug in the help file.

I can't see any bug in the code.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Current help file on the web.

FileCopy: "The destination path of the copied file(s)."

FileMove: "The destination path and filename of the moved file."

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

  On 1/27/2014 at 9:09 AM, water said:

Current help file on the web.

FileCopy: "The destination path of the copied file(s)."

FileMove: "The destination path and filename of the moved file."

I don't see the issue. Sorry. Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

It depends on how you define path:

If it is just drive and directories then the text in FileCopy implies that you can't specify a filename + extension.

If it is drive, directories plus filename/extension then the part "and filename" in FileMove is redundant.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Dear guiness,

If I understand Water correctly, the bug/issue is not in the code, it is in the help file.  You see, the help file makes it look like you cannot specify a different output filename, but according to Water, you actually can, and he gave an example.

As soon as I finish testing that, I'll mark Water's reply "solved"

  On 1/27/2014 at 9:11 AM, guinness said:

I don't see the issue. Sorry.

Posted

Thanks, water!

I think the help file should be modified to clarify the issue.

  On 1/27/2014 at 8:52 AM, water said:

That's a bug in the help file. You can copy and rename the file in one go.

$iResult = FileCopy(@ScriptDir & "\" & @Scriptname, @ScriptDir & "\test.xyz")
MsgBox(0, "Result", $iResult)

Copies the script file file with a new name. MsgBox displays "1" if successful.

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