Page 1 of 1
how to deal with selected files(help!)
Posted: 16 Jan 2010 07:59
by rongdorry
i am a newer.
now i want to create a script to backup selected files.
i tried
copyitem , "*_backup_<date yyyymmdd>.?";
but seems it only backup the only first file which i selected
can anyone help me?
Re: how to deal with selected files(help!)
Posted: 16 Jan 2010 11:42
by admin
Hi!
copyitem works on single items only (else I would have called it
copyitems 
).
So you want to make a copy of all selected items under a new name (defined by a pattern) in the same folder? I'm not among the top scripters here but I think this is currently not possible. If I'm right I will add it since it looks like a useful thing.
Don
Re: how to deal with selected files(help!)
Posted: 16 Jan 2010 12:35
by Stefan
I think right now you have to collect an list of files with
$items = getinfo("SelectedItemsPathNames", "|");
This script could work:
Code: Select all
$filelist = getinfo('SelectedItemsPathNames', '|'); //collect list of selected files
//get one time the current path
$file=gettoken($filelist, 1, "|");
$Path = regexreplace($file, "(.+)\\.+", "$1");
// for each file from list DO smtg:
$BatOutput = "";
$count = 1;
while(1)
{
$file=gettoken($filelist,$count,"|");
if("$file"==""){break;}
//split "path\file.ext" into "file" and "ext":
$Name = regexreplace($file, ".+\\(.+)\..*", "$1");
$Exte = regexreplace($file, ".+\.(.*)", "$1");
//compose new file name:
$Output = $Name . "_backup_<date yyyymmdd>" . '.' . $Exte;
// collect the output:
$BatOutput = $BatOutput . $Output<crlf>;
$count++;
}
// provide the output
text $BatOutput;
or with 'report'
Code: Select all
text report("{basename}_backup_<date yyyymmdd>.{ext}" . "<crlf>",1);
Thanks again for implementing {basename}
.
Re: how to deal with selected files(help!)
Posted: 16 Jan 2010 12:52
by admin
I will add a new command CopyAs pattern, [itemlist]
Re: how to deal with selected files(help!)
Posted: 16 Jan 2010 12:55
by jacky
You don't really need a loop to do this, another way that should do the work just fine :
Code: Select all
load report('copyitem "{Fullname}", "*_backup_<date yyyymmdd>.?"; ', 1),,s;
Re: how to deal with selected files(help!)
Posted: 17 Jan 2010 14:20
by rongdorry
jacky wrote:You don't really need a loop to do this, another way that should do the work just fine :
Code: Select all
load report('copyitem "{Fullname}", "*_backup_<date yyyymmdd>.?"; ', 1),,s;
ooh!it's really works fine.thanks!
Re: how to deal with selected files(help!)
Posted: 17 Jan 2010 16:53
by admin
rongdorry wrote:jacky wrote:You don't really need a loop to do this, another way that should do the work just fine :
Code: Select all
load report('copyitem "{Fullname}", "*_backup_<date yyyymmdd>.?"; ', 1),,s;
ooh!it's really works fine.thanks!
Yeah, that was really a very clever idea of jacky!
Anyway, in the next beta version (8.80.0027) you will be able to do just this to achieve the same thing:
Code: Select all
::copyas "*_backup_<date yyyymmdd>.?";