Page 1 of 1
script query for simple backup
Posted: 18 Feb 2015 15:27
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
Re: script query for simple backup
Posted: 20 Feb 2015 18:09
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"}
}
Re: script query for simple backup
Posted: 20 Feb 2015 19:49
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
Re: script query for simple backup
Posted: 21 Feb 2015 09:15
by bdeshi
Remove one underscore from the regex pattern in the first line: "^___.*" to "^__.*"
Re: script query for simple backup
Posted: 21 Feb 2015 20:27
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
Re: script query for simple backup
Posted: 21 Feb 2015 21:05
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.
Re: script query for simple backup
Posted: 22 Feb 2015 06:55
by bdeshi
sorry for my careless effort.
btw, my original script needed one more change in the form of substr(<curbase>,3) -> substr(<curbase>,2)
Re: script query for simple backup
Posted: 22 Feb 2015 14:59
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
Re: script query for simple backup
Posted: 22 Feb 2015 15:34
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>";
}
Re: script query for simple backup
Posted: 22 Feb 2015 15:50
by bdeshi
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;
}
Re: script query for simple backup
Posted: 22 Feb 2015 16:56
by calude
Thanks guys
both scripts work beautifully
Calude