Page 1 of 1
Rename and overwrite on move
Posted: 21 Jul 2022 14:15
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.
Re: Rename and overwrite on move
Posted: 21 Jul 2022 14:22
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;
Re: Rename and overwrite on move
Posted: 21 Jul 2022 14:57
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
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?
Re: Rename and overwrite on move
Posted: 21 Jul 2022 15:24
by highend
And because of this you need the setting "BackgroundFileOps", 0; line...
Re: Rename and overwrite on move
Posted: 21 Jul 2022 15:30
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.
Re: Rename and overwrite on move
Posted: 21 Jul 2022 15:40
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.