how to deal with selected files(help!)

Discuss and share scripts and script files...
Post Reply
rongdorry
Posts: 3
Joined: 16 Jan 2010 03:20

how to deal with selected files(help!)

Post 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?

admin
Site Admin
Posts: 64877
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: how to deal with selected files(help!)

Post by admin »

Hi!

copyitem works on single items only (else I would have called it copyitems :P ).

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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: how to deal with selected files(help!)

Post 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}


.

admin
Site Admin
Posts: 64877
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: how to deal with selected files(help!)

Post by admin »

I will add a new command CopyAs pattern, [itemlist]

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: how to deal with selected files(help!)

Post 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;
Proud XYplorer Fanatic

rongdorry
Posts: 3
Joined: 16 Jan 2010 03:20

Re: how to deal with selected files(help!)

Post 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!

admin
Site Admin
Posts: 64877
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: how to deal with selected files(help!)

Post 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! 8)

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>.?";

Post Reply