Page 10 of 41

Re: Scripting Bugs

Posted: 25 Sep 2009 15:25
by jacky
zer0 wrote:
admin wrote:There was indeed a side effect in a recent change. Fixed in next upload.

But, the dot (concatenator) in your pattern is reason enough to quote it. Because *.r?? is resolved to *r??.
Then the wiki (http://88.191.26.34/XYwiki/index.php/Sc ... _selfilter) needs to be changed, because, in an example mention in it, 1.gif (unquoted) is resolved as *1.gif* because no wildcards are mentioned in that pattern, so they're added automatically. However, there are wildcards in my pattern, so why is the effect of the concatenator different depending on presence of wildcards?
It is that way because it refers to selection filters, not the scripting command. So the examples are examples of selection filters and how they need to be used, which can be done from different places, one of them being the command selfilter.

Now, for that command as with any other command or function in XY scripting, (string) arguments should always be quoted.

That's also why in the examples of use below for selfilter, you have this:
selfilter "readme";
Selects all items whose name contains "readme" (eg: readme, readme.txt, !readme.now)

selfilter """readme""";
Selects item named "readme" and only that one item

Re: Scripting Bugs

Posted: 25 Sep 2009 15:48
by zer0
I see. From an abstract point of view, I'm wary of wildcards and quotes being put together to identify string arguments. In my mind, they are mutually exclusive. I'm glad that Don has fixed this issue and I look forward to making sure that it works.

Re: Scripting Bugs

Posted: 25 Sep 2009 15:57
by admin
zer0 wrote:
admin wrote:There was indeed a side effect in a recent change. Fixed in next upload.

But, the dot (concatenator) in your pattern is reason enough to quote it. Because *.r?? is resolved to *r??.
Then the wiki (http://88.191.26.34/XYwiki/index.php/Sc ... _selfilter) needs to be changed, because, in an example mention in it, 1.gif (unquoted) is resolved as *1.gif* because no wildcards are mentioned in that pattern, so they're added automatically. However, there are wildcards in my pattern, so why is the effect of the concatenator different depending on presence of wildcards?
1.gif (unquoted) is resolved as *1gif*, so the wiki is wrong here.

Re: Scripting Bugs

Posted: 25 Sep 2009 16:12
by jacky
admin wrote:1.gif (unquoted) is resolved as *1gif*, so the wiki is wrong here.
No it's not, read up. ;) 1.gif in the wiki here is given as a general pattern, not a scripting example, so just a selection filter, e.g. one you could use from Edit|Select|Selection Filter -- now we don't need to quote those, do we?
As I said, of course if you're gonna use this pattern with SC selftilter, as with any other argument in scripting, you'll need to quote it.

PS: Just in case you missed it, read up also for a scripting bug with continue and else(if) blocks...

Re: Scripting Bugs

Posted: 25 Sep 2009 16:15
by admin
jacky wrote:
admin wrote:1.gif (unquoted) is resolved as *1gif*, so the wiki is wrong here.
No it's not, read up. ;) 1.gif in the wiki here is given as a general pattern, not a scripting example, so just a selection filter, e.g. one you could use from Edit|Select|Selection Filter -- now we don't need to quote those, do we?
As I said, of course if you're gonna use this pattern with SC selftilter, as with any other argument in scripting, you'll need to quote it.

PS: Just in case you missed it, read up also for a scripting bug with continue and else(if) blocks...
Ah! :oops: No, did not read it up. And also missed the continue bug... :roll: , TGIF!

Re: Scripting Bugs

Posted: 25 Sep 2009 16:24
by zer0
jacky wrote:No it's not, read up. ;) 1.gif in the wiki here is given as a general pattern, not a scripting example...
...then why is it on the page for selfilter scripting command? That clearly creates a confusion. Yes, selfilter means Selection Filter that's accessible elsewhere, so on that respective page there should not be any quotes. I'm just glad that in my case quotes aren't mandatory and Don said that scripting command not working was a side-effect, so I'll carry on avoiding quotes unless I can't help it :P

Re: Scripting Bugs

Posted: 25 Sep 2009 17:13
by Muroph
zer0 wrote:I'm just glad that in my case quotes aren't mandatory and Don said that scripting command not working was a side-effect, so I'll carry on avoiding quotes unless I can't help it :P
from my experience i'd say you shouldn't do this. really.
you DON'T want to accidentally nuke the wrong files because of missing quotes, like i did. :x

BTW, i don't think the wiki is confusing.
one section has pattern examples, and the other shows how they are used in scripts.
nothing wrong there.

Re: Scripting Bugs

Posted: 25 Sep 2009 17:19
by admin
Quoting the Help file:
Using Quotes in Scripting

It's strongly recommended that you (double- or single-) quote your strings! While the script engine is currently still permissive with unquoted strings (msg Hi! works) this might not be so in the future, so you better do msg "Hi!" right away!

Re: Scripting Bugs

Posted: 25 Sep 2009 18:09
by jacky
What they said. Besides, I think what Don actually said was that, in this case, quotes were actually required, as without them your filter isn't what you think it is/want it to be :
admin wrote:But, the dot (concatenator) in your pattern is reason enough to quote it. Because *.r?? is resolved to *r??.

Re: Scripting Bugs

Posted: 25 Sep 2009 18:26
by zer0
My grudge with quotes is that [when single-quoting] there is no indication of wildcards being added while they are. For example, "temp.rar" and "*temp.rar*" do the same thing while they are not the same. Is that the correct behaviour? I don't think so. Wrapping a string in TRIPLE quotes to get an exact match is incomprehensible. Personally, I'd rather use "temp.rar" pattern and not catch "temporary.rar" in my folder than battle with so many quotes. I think it's a matter of getting exactly what you asked for: you asked for temp.rar, you got temp.rar, you didn't specify any wildcards so none were applied. I spoke to a German colleague yesterday and he said that they are very direct in terms of dealing with things, ja? :mrgreen:

Re: Scripting Bugs

Posted: 25 Sep 2009 18:43
by jacky
zer0 wrote:My grudge with quotes is that [when single-quoting] there is no indication of wildcards being added while they are. For example, "temp.rar" and "*temp.rar*" do the same thing while they are not the same. Is that the correct behaviour? I don't think so.
Of course it is, it's a feature! ;) Because most of the time you'd want to type part of the filename, so XY defaults there while of course still allowing exact match through the use of quotes. (Something that, IIRC, Windows Explorer simply cannot do...)
zer0 wrote:Wrapping a string in TRIPLE quotes to get an exact match is incomprehensible.
For an exact match you need to use quotes in your pattern, e.g. "foobar" which, obviously, used in scripting, means your pattern is an argument that must be quoted -- so either """foobar""" or '"foobar"'

I think you might be confusing what you actually write in your script, and what the pattern/filter really is.

Code: Select all

selfilter "foobar"; // pattern is foobar
selfilter '"foobar"'; // pattern is "foobar"

Re: Scripting Bugs

Posted: 26 Sep 2009 10:35
by zer0
Aha! Assuming that most of the time I'd type a part of a name is where the issue is. I wouldn't, simple as that. You've no idea how many times I've wanted to pull my hair out when searching and finding partial matches, but not exact ones as a result of the default action.. I guess it's partially intuitive :)

Also, I've reconstructed my older script to follow the pattern of the one that you suggested, but now it does not move the files to their destinations. I stepped through it and it gets as far as the match of pattern and recognises where to move, but doesn't get to the bottom of the script to actually move the files. Here it is in full:

Code: Select all

"New Moving Script"
   $filelist = getinfo('SelectedItemsPathNames', '|');
   $p = strpos($filelist, '|');
   while ($p >= 0)
   {
      $file = substr($filelist, 0, $p);
      $name = regexreplace($file, "^.+\\(.+)$", "$1");
      $filelist = substr($filelist, $p + 1);
      $p = strpos($filelist, '|');
      //
      $dest = FALSE;
      if (strpos($name, '.720p.HDTV.') > -1)
      {
         $dest = 'D:\Video\TV 720p\';
      }
      elseif (strpos($name, 'CSI.S10') > -1)
      {
         $dest = 'D:\Video\CSI Las Vegas\';
      }
      elseif (strpos($name, 'Smallville') > -1)
      {
         $dest = 'D:\Video\Smallville\';
      }
      elseif (strpos($name, 'The.Office') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'Supernatural.') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'Greys.Anatomy') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, '90210.S02') > -1)
      {
         $dest = 'D:\Video\90210\';
      }
      elseif (strpos($name, 'American.Dad') > -1)
      {
         $dest = 'D:\Video\American Dad\';
      }
      elseif (strpos($name, 'The.Big.Bang.Theory') > -1)
      {
         $dest = 'D:\Video\The Big Bang Theory\';
      }
      elseif (strpos($name, 'CSI.Miami') > -1)
      {
         $dest = 'D:\Video\CSI Miami\';
      }
      elseif (strpos($name, 'CSI.NY.') > -1)
      {
         $dest = 'D:\Video\CSI NY\';
      }
      elseif (strpos($name, 'CSI.New.York') > -1)
      {
         $dest = 'D:\Video\CSI NY\';
      }
      elseif (strpos($name, 'Daily.Show') > -1)
      {
         $dest = 'D:\Video\Daily Show\';
      }
      elseif (strpos($name, 'Family.Guy') > -1)
      {
         $dest = 'D:\Video\Family Guy\';
      }
      elseif (strpos($name, 'Fringe.') > -1)
      {
         $dest = 'D:\Video\Fringe\';
      }
      elseif (strpos($name, 'Gossip.Girl') > -1)
      {
         $dest = 'D:\Video\Gossip Girl\';
      }
      elseif (strpos($name, 'Heroes.') > -1)
      {
         $dest = 'D:\Video\Heroes\';
      }
      elseif (strpos($name, 'House.') > -1)
      {
         $dest = 'D:\Video\House\';
      }
      elseif (strpos($name, 'Jay.Leno') > -1)
      {
         $dest = 'D:\Video\Jay.Leno\';
      }
      elseif (strpos($name, 'Law.and.Order.SVU') > -1)
      {
         $dest = 'D:\Video\LaO SVU\';
      }
      elseif (strpos($name, 'NCIS') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'One.Tree.Hill') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'The.Mentalist') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'The.SImpsons') > -1)
      {
         $dest = 'D:\Video\The Simpsons\';
      }
      elseif (strpos($name, 'Law.and.Order.S') > -1)
      {
         $dest = 'D:\Video\LaO\';
      }
      elseif (strpos($name, 'Desperate.Housewives') > -1)
      {
         $dest = 'D:\Video\Desperate.Housewives\';
      }
      elseif (strpos($name, 'How.I.Met.Your.Mother') > -1)
      {
         $dest = 'D:\Video\How I Met Your Mother\';
      }
      elseif (strpos($name, 'Hells.https://www.xyplorer.com.US.') > -1)
      {
         $dest = 'D:\Video\Hell'https://www.xyplorer.com\';
      }
      elseif (strpos($name, 'Flashpoint.') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      elseif (strpos($name, 'South.Park') > -1)
      {
         $dest = 'D:\Video\South Park\';
      }
      elseif (strpos($name, 'Cops.') > -1)
      {
         $dest = 'D:\Video\Cops\';
      }
      elseif (strpos($name, 'Dollhouse.') > -1)
      {
         $dest = 'D:\Video\USTV\';
      }
      
      if (FALSE != $dest)
      {
         moveto $dest, $file;
      }
   

Re: Scripting Bugs

Posted: 26 Sep 2009 15:08
by admin
jacky wrote:Unrelated: found a bug in scripting: From the help

Code: Select all

// script will only show "done"
  $i = 1;
  while ($i <= 3) {
    $i++;
    continue;
    echo $i;
  }
  echo "done";
Works as expected. Now this should do the same, but doesn't as continue; seem to escape the else block only, and we need to do continue 2; to make it work properly...

Code: Select all

// script will show "2", "3, "4", "done"
  $i = 1;
  while ($i <= 3) {
    $i++;
    if (0) {} else { continue; }
    echo $i;
  }
  echo "done";
FYI the key is the else, it works fine within an if block. However, from an elseif block it is buggy as well...
Confirmed and fixed, merci!

Re: Scripting Bugs

Posted: 27 Sep 2009 13:24
by jacky
zer0 wrote:Also, I've reconstructed my older script to follow the pattern of the one that you suggested, but now it does not move the files to their destinations. I stepped through it and it gets as far as the match of pattern and recognises where to move, but doesn't get to the bottom of the script to actually move the files. Here it is in full:
Okay I see 2 problems in this script :
- Maybe a copy/paste error, but you're missing the closing bracket (of the while loop) at the end
- you forgot to escape a single quote in that line:

Code: Select all

$dest = 'D:\Video\Hell'https://www.xyplorer.com\';
Should be this::

Code: Select all

$dest = 'D:\Video\Hell''https://www.xyplorer.com\';

Re: Scripting Bugs

Posted: 27 Sep 2009 13:36
by zer0
Thank you jacky! Those two issues were the cause of my headaches 8)