Make backups in one folder with changed names

Discuss and share scripts and script files...
Post Reply
Alter
Posts: 1
Joined: 22 Feb 2021 22:17

Make backups in one folder with changed names

Post by Alter »

Hello! I searched forum and haven't found anything that meets my criteria, and I'm complete noob at scripting, so here I am.
I want to make backups of selected files in Backups folder with names changed to meet a key. Basically:

I highlight files, for example:
C:/Files/Home_picture.jpg
C:/Files/Program.exe

Script creates folder in that root called Backups
C:/Files/Backups

Copies selected files, and pastes them in Backups folder with changed names meeting a key [filename_backup.extension], for example
C:/Files/Backups/Home_picture_backup.jpg
C:/Files/Backups/Program_backup.exe

If i select new files and folder Backups already exist in their folder, it copies inside it instead.

I hope something like this could be done. Thanks in advance!

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Make backups in one folder with changed names

Post by highend »

Code: Select all

    $items     = <get SelectedItemsNames <crlf>>;
    $subExists = (exists("<curpath>\Backup") == 2) ? 1 : 0;
    if (!$subExists) { new("Backup", "dir"); }

    foreach($item, $items, <crlf>, "e") {
        if (exists($item) == 2) { continue; }

        // Backup subfolder already exists
        if ($subExists) {
            copyitem "<curpath>\$item", "<curpath>\Backup\$item";

        // Backup subfolder doesn't exist
        } else {
            copyitem "<curpath>\$item", "<curpath>\Backup\" . gpc($item, "base") . "_backup" . "." . gpc($item, "ext");
        }
    }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Alter
Posts: 1
Joined: 22 Feb 2021 22:17

Re: Make backups in one folder with changed names

Post by Alter »

Thank you very much! Works like a charm
Last edited by Alter on 23 Feb 2021 07:58, edited 1 time in total.

Horst
Posts: 1080
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Make backups in one folder with changed names

Post by Horst »

Alter wrote: 23 Feb 2021 07:57 Thank you very much! Works like a charm
Why not making something like _date_time instead of _backup.
Then you can have multiple versions of each file in the backup sub-dir.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3235)
Portable XYplorer (actual version, including betas)
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69

Post Reply