Rename and overwrite on move

Discuss and share scripts and script files...
Post Reply
Arikdefrasia
Posts: 10
Joined: 10 Jun 2022 17:35

Rename and overwrite on move

Post by Arikdefrasia »

I'm trying my best to figure this out on my own, but with zero knowledge on what any of it actually means or does, I'm just getting dubious syntax over and over.

I need to copy a file (mpv-1.dll) to a folder on a different drive and rename it to mpv-2.dll and overwrite the pre-existing file.

So far I've got

Code: Select all

backupto "C:\Program Files\Plex\Plex\", "D:\Program Files\SVP 4\mpv64\mpv-1.dll", "OverwriteExisting", 
but can't figure out the rename portion without syntax errors.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename and overwrite on move

Post by highend »

backupto can't rename a file, the first argument is a path only...
Check if the file exists, delete it, copy it over while giving it a new name...

Code: Select all

    $srcFile = "D:\Program Files\SVP 4\mpv64\mpv-1.dll";
    $dstFile = "C:\Program Files\Plex\Plex\mpv-2.dll";

    setting "BackgroundFileOps", 0;
    if (exists($dstFile) == 1) { delete 1, 0, $dstFile; }
    copyitem $srcFile, $dstFile;
One of my scripts helped you out? Please donate via Paypal

Arikdefrasia
Posts: 10
Joined: 10 Jun 2022 17:35

Re: Rename and overwrite on move

Post by Arikdefrasia »

highend wrote: 21 Jul 2022 14:22 backupto can't rename a file, the first argument is a path only...
Check if the file exists, delete it, copy it over while giving it a new name...
I'm not entirely sure how, but I managed to make it work with this script

Code: Select all

backupto "C:\Program Files\Plex\Plex\", "D:\Program Files\SVP 4\mpv64\mpv-1.dll"; renameitem("mpv-2", "C:\Program Files\Plex\Plex\mpv-1.dll", 8,);
The only downside being if mpv-1 doesn't already exist at the target destination, it tries to rename before the backupto has a chance to do it's job and says that the file doesn't exist.

But yeah your script is much smoother; I'm just not sure what any of it means. Please forgive my ignorance, let me see if I understand this correctly.

So

Code: Select all

    $srcFile = "D:\Program Files\SVP 4\mpv64\mpv-1.dll";
    $dstFile = "C:\Program Files\Plex\Plex\mpv-2.dll";
defines what the $srcFile and $dstFile are for the following commands right?

So then

Code: Select all

setting "BackgroundFileOps", 0;
activates xycopy but what is the 0?

Code: Select all

 if (exists($dstFile) == 1) { delete 1, 0, $dstFile; }
alright so the "if (exists" and "{ delete" is pretty straightforward, but what does "== 1" and "1, 0," stand for?

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename and overwrite on move

Post by highend »

And because of this you need the setting "BackgroundFileOps", 0; line...
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename and overwrite on move

Post by highend »

Sorry but I don't have time to explain single arguments. All of them are documented in the help file for each of these commands.

E.g.:
activates xycopy but what is the 0?
No. It disables all background file operations. Why is that necessary? Because e.g. delete is not a function, it doesn't have a return value. XY doesn't wait until it's finished but executes the next command immediately. And the same happens on your script with backupto. renameitem() is called immediately regardless if backupto has finished it's job or not.
One of my scripts helped you out? Please donate via Paypal

Arikdefrasia
Posts: 10
Joined: 10 Jun 2022 17:35

Re: Rename and overwrite on move

Post by Arikdefrasia »

highend wrote: 21 Jul 2022 15:30 Sorry but I don't have time to explain single arguments. All of them are documented in the help file for each of these commands.

E.g.:
activates xycopy but what is the 0?
No. It disables all background file operations. Why is that necessary? Because e.g. delete is not a function, it doesn't have a return value. XY doesn't wait until it's finished but executes the next command immediately. And the same happens on your script with backupto. renameitem() is called immediately regardless if backupto has finished it's job or not.
...okay now I'm really lost, but you've been more than helpful. Thank you so much for your time.

Post Reply