File name / Folder name select

Discuss and share scripts and script files...
CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

I've tried the EqualTo operation, the Like operation and a few more, none of them work.

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("<filename>" == $folder) {
            selectitems $folder, , 0, "a";
        }
    }

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("<filename>" && $folder) {
            selectitems $folder, , 0, "a";
        }
    }

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("<filename>" Like $folder) {
            selectitems $folder, , 0, "a";
        }
    }

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: File name / Folder name select

Post by TheQwerty »

Without knowing enough about what you're trying to match....

Code: Select all

$folder Like "<curbase>*"
Unfortunately, a.txt will select a, a-files, alpha, and alpha-files.
If it were always ending with -files then you could use <curbase>-files instead, and even make it == instead of like.
If instead the files part can differ but the - is always a separator (and not possibly part of <curbase>) you can use <curbase>-* with the like.

Failing those there is no select-items-which-are-the-same-but-not command which will magically read your mind - you'll have to write your own code to determine the similarity between two strings.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

TheQwerty wrote:Without knowing enough about what you're trying to match....

Code: Select all

$folder Like "<curbase>*"
Unfortunately, a.txt will select a, a-files, alpha, and alpha-files.
If it were always ending with -files then you could use <curbase>-files instead, and even make it == instead of like.
If instead the files part can differ but the - is always a separator (and not possibly part of <curbase>) you can use <curbase>-* with the like.

Failing those there is no select-items-which-are-the-same-but-not command which will magically read your mind - you'll have to write your own code to determine the similarity between two strings.
The folders always end with the suffix in the folder name "-files" including the dash. In other words [filenameA1-files] curbase could select the matching folder to the file, not all matching folders as it was doing ?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: File name / Folder name select

Post by TheQwerty »

CookieMonster wrote:The folders always end with the suffix in the folder name "-files" including the dash. In other words [filenameA1-files] curbase could select the matching folder to the file, not all matching folders as it was doing ?
Then you have your answer.. case closed!

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

I created a User-Defined Command, I also read on <curbase> within XYplorer Native Variables, doesn't seem difficult, but where do I place it ?

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

I don't understand how to use <curbase> could someone please help ?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: File name / Folder name select

Post by TheQwerty »

<curbase> is just a variable which is replaced with the base name, portion of the name before any extension, of the currently selected and focused item.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("RoboSheep" == <curbase>-files) {
            selectitems $folder, , 0, "a";
        }
    }
Not the correct use of the syntax !

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

Re: File name / Folder name select

Post by highend »

Will RoboSheep EVER match anything that has any kind of name concatenated with "-files"...
Probably...

Btw, you can count up to 1? That's the exact amount of files that will be compared (TheQwerty was already clear enough on that subject)...
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: File name / Folder name select

Post by TheQwerty »

CookieMonster wrote:

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("RoboSheep" == <curbase>-files) {
            selectitems $folder, , 0, "a";
        }
    }
Not the correct use of the syntax !
Your are correct in that this is not correct.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

TheQwerty wrote:
CookieMonster wrote:

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("RoboSheep" == <curbase>-files) {
            selectitems $folder, , 0, "a";
        }
    }
Not the correct use of the syntax !
Your are correct in that this is not correct.
Great, what is the correct way to use the syntax ?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: File name / Folder name select

Post by TheQwerty »

CookieMonster wrote:
TheQwerty wrote:
CookieMonster wrote:

Code: Select all

foreach($folder, listpane( ,"*", 6)) {
        if ("RoboSheep" == <curbase>-files) {
            selectitems $folder, , 0, "a";
        }
    }
Not the correct use of the syntax !
Your are correct in that this is not correct.
Great, what is the correct way to use the syntax ?
Depends on what you're trying to do... Try stepping through it to see where you've gone wrong.

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

If <curbase> is a variable, all within a few minutes I've tried a few things to the condition, everything I've tried doesn't work. Declaring <curbase> as a variable doesn't seem right !

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

Re: File name / Folder name select

Post by Stefan »

Try this.

Step by Step to understand.

Select your file, then execute this script:
1)

Code: Select all

$base = "<curbase>";
    msg $base;


Next step.
Select your file, then execute this script:
2)

Code: Select all

$base = "<curbase>";
   msg $base;
   $folder = "$base-files";
   msg $folder;



Now the full script.
Select your file, then execute this script:
3)

Code: Select all

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

Or shorter.
Select your file, then execute this script:

Code: Select all

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

Or, if you are sure to always select a file first:

Select your file, then execute this script:

Code: Select all

     selectitems "<curbase>-files";

See the help for more parameters.

HTH? :D

CookieMonster

Re: File name / Folder name select

Post by CookieMonster »

Stefan - Thanks that helped me make sense of the scripting in XYplorer, and now I know partially what you did by defining variables etc.

Code: Select all

if(exists("<curitem>") == 1){
     $base = "<curbase>";
     $folder = "$base-files";
     selectitems $folder + $base;
  }else{msg "this is not a file";}
The script doesn't select simultaneously select the folder when I select a file and run the script, I tried adding the two variables together in hopes that when I select the files then run the script, it would select the matching folders.

Post Reply