script query for simple backup

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

script query for simple backup

Post by calude »

hi
dear Script yodas
please help me with this probably simple one


select this folder"___mywebsite"
backup it in same location.
and rename the backup "mywebsite_01"

merci beaucoup


Calude

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: script query for simple backup

Post by bdeshi »

[first of all, sorry for the delay]

Here's a script (very particular to this job). It will backup a selected folder whose name matches ___* pattern and copy it as *_01 in the selected folder's parent location. No overwriting, no auto-suffixing.

Code: Select all

 if (exists(<curitem>)==2) && (regexmatches(<curbase>, "^___.*") != "") {
  if !exists(getpathcomponent(<curitem>,path).'\'.substr(<curbase>,3)."_01"){
   copyas substr(<curbase>,3)."_01", gettoken(<curitem>,path), <curitem>;
  } else {echo "destination already exists<crlf 2>".getpathcomponent(<curitem>,path).'\'.substr(<curbase>,3)."_01"}
 }
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: script query for simple backup

Post by calude »

thanks a lot Sammay

works as intended, except the original folder name was (my mistake) "__GN2" (2 underscores) therefore I got "N2_01"
can you explain what to correct.

again merci beaucoup

Calude

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: script query for simple backup

Post by bdeshi »

Remove one underscore from the regex pattern in the first line: "^___.*" to "^__.*"
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: script query for simple backup

Post by calude »

SammaySarkar wrote:Remove one underscore from the regex pattern in the first line: "^___.*" to "^__.*"
Hi again
I did remove one underscore in the first line
but with "__GN2"
I got "N2_01"
the "G" was truncated

have a nice week-end
Calude

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

Re: script query for simple backup

Post by highend »

Code: Select all

    if (exists("<curitem>") == 2) && (regexmatches("<curbase>", "^_+")) {
        $newName = regexreplace("<curbase>", "^_+") . "_01";
        if !(exists("<curpath>\$newName")) {
            copyas $newName, , "<curitem>";
        } else { echo "Destination already exists:<crlf 2>" . "<curpath>\$newName"; }
    }
This one would work for all folders that begin with a single underscore. If it's necessary that two are required, double the underscore in the regexmatches part on the first line.
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: script query for simple backup

Post by bdeshi »

sorry for my careless effort. :oops:

btw, my original script needed one more change in the form of substr(<curbase>,3) -> substr(<curbase>,2)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: script query for simple backup

Post by calude »

Sammay, Highend
both script work
until
I start it a second time and all I get is a warning saying "Destination already exists"
instead of incrementing backup GN2_01 to GN2_02 etc...
I dont need any warning its a backup/versions procedure

Calude

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

Re: script query for simple backup

Post by highend »

Code: Select all

    if (exists("<curitem>") == 2) && (regexmatches("<curbase>", "^_+")) {
        $newBaseName = regexreplace("<curbase>", "^_+");
        $lastEntry = gettoken(listfolder(, "$newBaseName*", 2+4), -1, "|");
        if ($lastEntry) { $newName = $newBaseName . "_" . format(regexmatches($lastEntry, "\d+$") + 1, "00"); }
        else            { $newName = $newBaseName . "_01"; }
        copyas $newName, , "<curitem>";
    }
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: script query for simple backup

Post by bdeshi »

:mrgreen:
And here's mine!

Code: Select all

 setting backgroundfileops, 0;
 if (exists(<curitem>)==2) && (regexmatches(<curbase>, "^__.*") != "") {
  $incr = '01';
  while (exists(getpathcomponent(<curitem>,path).'\'.substr(<curbase>,2).'_'.$incr) != 0) {
   $incr = $incr + 1;   $incr = (strlen($incr)!=2)?('0'.$incr):($incr);
  }
  copyas substr(<curbase>,2).'_'.$incr, gettoken(<curitem>,path), <curitem>;
  wait 50; status "backed up"; wait 50;
 }
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: script query for simple backup

Post by calude »

Thanks guys
both scripts work beautifully
:beer: :beer: :beer:
:appl:
Calude

Post Reply