File name / Folder name select

Discuss and share scripts and script files...
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: File name / Folder name select

Post by Stefan »

CookieMonster wrote: selectitems $folder + $base;
What should that do? Keep the file selected AND select the corresponding folder additionally too?

Then just take a look into the help about scripting:
//Syntax:
//selectitems itemlist, [flags], [focusfirst=1], [mode], [pane]

mode
n: [Default] New selection (drop current selections).
a: Add the matches to any current selections.
r: Remove the matches from any current selections.

And adjust the code to:

selectitems $folder , , , a;


Select your file and execute this code:

Code: Select all

if(exists("<curitem>") == 1){
     $base = "<curbase>";
     $folder = "$base-files";

     //selectitems itemlist, [flags], [focusfirst=1], [mode], [pane]
     selectitems $folder , , , a;
  }else{msg "this is not a file";}



Or in short

Select your file and execute this code:

Code: Select all

  if(exists("<curitem>") == 1){
     selectitems "<curbase>-files" , , , a;
  }else{msg "this is not a file";}



If you don't understood what this does, you may want to read the first posts from the scripting forum and the help file about scripting.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

Stefan it works nice except it only selects one pair of files & folders. In other words I select a file called <acme35> running the script selects the folder called <acme34>-files. One pair, if I select (20) files and the script is suppose to find the matching folders the script won't do this.

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

Re: File name / Folder name select

Post by Stefan »

CookieMonster wrote:Stefan it works nice except it only selects one pair of files & folders.
In other words I select a file called <acme35> running the script selects the folder called <acme34>-files.
One pair, if I select (20) files and the script is suppose to find the matching folders the script won't do this.
That is correct.
That is how THIS script works.
( and please see how many effort I have put into formatting your post, to be able to better get what you want :whistle:
That's how I suspect others to format there post, especial if they asking for help :wink: )



If you want something other, you have to tell what you want and how you want it to work.


In this example: how would you work?
Do you want to
- select more than one file by hand
- execute the script, and every selected files AND the corresponding folders are become selected too?

Then we would just put something like this


$FILES = get("SelectedItemsPathNames", "|");
foreach( $file, $FILES){

}


around the script.


That would result in such working script:

Code: Select all

  //get list of names of all selected files:
  $FILES = get("SelectedItemsPathNames", "|");

  //for each file in the list, do something:
  foreach( $file, $FILES){

      //if this is a file (and not a folder):
      if(exists($file) == 1){

         //get the base name (without extension):
         $base =  getpathcomponent($file, "base");
         //add the string '-files':
         $folder = "$base-files";
         //additionally select the corresponding folders too:
         selectitems "$folder" , , , a;
      }
  }






Or do you think about something different?

There are probably work flows I am not thinking off. So tell us what and how.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

Not only does the script work, but I have some insight into scripting within XYplorer, that's not to say I'm able to make amazing works of code, but it helps to have some light, then no light :)

Thank you !

Post Reply