Scripting question: copying a file and then renaming it - How done easiest?

Started by ubacher, April 01, 2015, 04:06:45 AM

Previous topic - Next topic

ubacher

Scripting question:
I like to copy a file to another folder and rename it -

   Database.CopyFile (f,to_folder)
Database.RenameFile (f,f.Name+"_copy"+f.Ext)

   
This renames the original file and not the copy.
What is the easiest way to rename the copied file??
( more precisely: easiest way to achieve this)



Carlo Didier

Your script copies file f and the renames file f.
You need to first select the copy and then rename that.

ubacher

QuoteYou need to first select the copy and then rename that.

That I thought to be the great difficulty. But on actually trying it it actually works out
as a simple one-line statement (+ error checking)
Here it is:
Set fcopy =Database.GetFiles(Folder+"\"+f.NameExt)
If fcopy.Count <> 1 Then
MsgBox("BUG: multiple or no files to rename")
End If
Database.RenameFile (fcopy(1),f.Name+"_copy"+f.Ext)


Where fcopy is of type files and Folders is the path to the new folder as string, which I have already.

The need to reply to Carlo made me look at the problem anew and so I found it was easy after all.
Thank you Carlo.

Carlo Didier

Quote from: ubacher on April 01, 2015, 01:39:44 PMThe need to reply to Carlo made me look at the problem anew and so I found it was easy after all.
Thank you Carlo.

As an IT pro myself, this happened very often to me. Being stuck in a problem, I tried to explain it to someone else (even if that person had no idea what I was talking about), and by that, I re-thought the whole thing and found the solution myself (with the other person still looking lost ...).


sinus

Quote from: Carlo Didier on April 01, 2015, 01:51:16 PM
As an IT pro myself, this happened very often to me. Being stuck in a problem, I tried to explain it to someone else (even if that person had no idea what I was talking about), and by that, I re-thought the whole thing and found the solution myself (with the other person still looking lost ...).

Hmmmm ... I have to rethink about the whole behaviour of my wife: she tells me also often something, and I do - I guess - looking lost!  8) ;D
Best wishes from Switzerland! :-)
Markus

Carlo Didier

Quote from: sinus on April 01, 2015, 03:08:25 PMHmmmm ... I have to rethink about the whole behaviour of my wife: she tells me also often something, and I do - I guess - looking lost!  8) ;D
Which proves that what she says isn't really meant for you ...  8)