Page 2 of 2

Re: I need script that mass renames SRTs using AVI file basename

Posted: 05 Nov 2010 22:56
by zer0
To make sure it's the AVI file that is selected, I've used this line:

Code: Select all

Selfilter "*.avi", f;
As for pasting, make sure the indentation is correct -- after the 1st line, all subsequent lines need at least 1 space from the left edge. This is how the parser knows those lines are part of the same script.

Any more problems? :D

Re: I need script that mass renames SRTs using AVI file basename

Posted: 05 Nov 2010 23:16
by xyka
zer0 wrote:To make sure it's the AVI file that is selected, I've used this line:

Code: Select all

Selfilter "*.avi", f;
As for pasting, make sure the indentation is correct -- after the 1st line, all subsequent lines need at least 1 space from the left edge. This is how the parser knows those lines are part of the same script.

Any more problems? :D
Good to know :D

Code: Select all

Selfilter "*.avi", f;
  $a = "<curbase>";
  Selfilter "*.srt", f;
  copyto ("1");
  rename b, $a;
  rename b, "*.ENG2";

Script is working well only if the avi has been selected before starting script.

ELSE:
Selfilter "*.avi", f; selects the avi file

but $a doesn't get the base name of the avi.

.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 05 Nov 2010 23:26
by zer0
xyka wrote:

Code: Select all

Selfilter "*.avi", f;
  $a = "<curbase>";
  Selfilter "*.srt", f;
  copyto ("1");
  rename b, $a;
  rename b, "*.ENG2";

Script is working well only if the avi has been selected before starting script.

ELSE:
Selfilter "*.avi", f; selects the avi file

but $a doesn't get the base name of the avi.

.
What file is selected in that folder prior to launching the script shouldn't make any difference as the very first line takes care of selecting the AVI file.

As for the base name, already replied here: http://www.xyplorer.com/xyfc/viewtopic. ... 300#p54300

Re: I need script that mass renames SRTs using AVI file basename

Posted: 05 Nov 2010 23:36
by xyka
Continued here from the bug thread:
zer0 wrote:It's not. Select any file and run this script

Code: Select all

$a = "<curbase>"; msg $a;
You will get the base name of that selected file.
Yes, but you select file manually.




It might be a bug.


Try this: put a New Textfile.txt file and a .rar file into a folder and select .rar file and run this script:

Code: Select all

Selfilter "*.txt", f; $a = "<curbase>"; msg $a;

result = NOTHING


select .txt file and run this same script:

Code: Select all

Selfilter "*.txt", f; $a = "<curbase>"; msg $a;
result = New Textfile



<curext>

<curname>

does the same too



BUT


Changing "<curbase>" to "<curpath>"

Code: Select all

Selfilter "*.txt", f; $a = "<curpath>"; msg $a;
is working in both cases.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 00:49
by zer0
You don't need to post the same thing in 2 different places ;)

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 01:33
by TheQwerty
Just to clarify and re-explain some things...

As was pointed out and is listed in the XYplorer Native Variables section of the help file: <curbase> and many of the other <cur...> variables return data only for the currently selected AND focused item.

SelFilter does not change the focus, so unless the focused item matches the pattern and thus gets selected those variables will not return anything useful in this case.

Thankfully, an easy way to work around this was just introduced in v9.60.0116 with the new command "Focus First Selected Item". So if you open Tools->Customize Keyboard Shortcuts, select the Miscellaneous Category, and then locate the Command "Focus First Selected Item" under "Focus Functions", you can see in the middle of the dialog at the bottom a number (#1048) which you can use in your script after the SelFilter to execute that command; like so:

Code: Select all

Selfilter "*.txt", f;#1048; $a = "<curbase>"; msg $a;

Now a comment... SelFilter is really meant to select multiple items, which means if it matches more than one item then the above code (with #1048) will only get you the <curbase> for the first item in the list. If you wanted to retrieve the base for all of the selected items you'd need to use

Code: Select all

Report "{Basename}|",1;
Where {Basename} is the Report template variable. '|' is a delimiter we want inserted after each base name and the argument 1 means only generate a report for the selected items.

What I suspect might work best for you though is to instead use the Sel command:

Code: Select all

Sel "[*.txt]", 1, 1; $a = "<curbase>"; msg $a;
Which will focus and select the first item from the top/start of the list which matches '*.txt' but not select any other items that may also match.

When using the Sel command with a pattern you must surround the match pattern with '[...]', and then we are saying select 1 item, and start from the top.

HTH!

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 07:49
by xyka
TheQwerty

thanks for the explanation


Selected and focused are two different thing.

And what is your opinion about this:

Code: Select all

Selfilter "*.srt", f; $a = Report ("{Basename}",1); msg $a;




Not an easy task to write a script.

There are so many "variables" to consider.




My script so far looks like this:

Code: Select all

Sel "[*.avi]", 1, 1;
  $a = "<curbase>";
  Sel "[*.srt]", 1, 1;
  copyto ("1");
  rename b, $a;
  rename b, "*.ENG2";
it works

problem might occur when there will be more .srt files

we will see when get there

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 09:19
by j_c_hallgren
xyka: Could you kindly do us a favor and limit the amount of blank lines in your posts? It makes it harder to read because one can't see most of, or entire post without scrolling on smaller screens.

Use TheQwerty and zer0's posts as a guide for spacing that is enough so it's not all 'smushed' together but not too much either.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 09:44
by xyka
j_c_hallgren wrote:xyka: Could you kindly do us a favor and limit the amount of blank lines in your posts? It makes it harder to read because one can't see most of, or entire post without scrolling on smaller screens.

Use TheQwerty and zer0's posts as a guide for spacing that is enough so it's not all 'smushed' together but not too much either.
I try to use fewer blank lines next time.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 12:24
by xyka
1. Add-ons for Firefox
2. Extensions
3. CHM Reader

CHM Reader 0.2.3

Code: Select all

https://addons.mozilla.org/en-US/firefox/addon/3235/

@TheQwerty, this focus command looks enough for me in the first steps.

Tools -> Customize Keyboard Shortcuts -> Category: Miscellaneous
-> Focus Functions -> Focus First Selected Item
Description:
In the List, move the focus to the first selected item from top,
and move it into view if necessary.
Command ID:
#1048;


<curitem> current (selected & focused) list item (full path)

WinRAR Help.chm -> Command line mode -> Commands -> Alphabetic commands list
e
Extract archived files, ignoring paths, to the current or a specified folder.


@zer0, Winrar doesn't unrar file if I use your run command

Here is what works:
Selfilter "angol", f;#1048;
run "C:\Program Files\WinRAR\WinRAR.exe" "e" "<curitem>",,1;

START FOLDER:
1
Stargate Universe - 02x06 - Trial and Error.FQM.En.srt
Stargate Universe s02e06 (hdtv-fqm) magyar.zip
Stargate Universe s02e06 (hdtv-fqm, 720p-ctu) angol.zip
stargate.universe.s02e06.hdtv.xvid-fqm.avi

SCRIPT:

Code: Select all

Selfilter "*.avi", f;#1048;
  $a = "<curbase>";
  Selfilter "*.srt", f;#1048;
  copyto ("1");
  rename b, $a;
  rename b, "*.ENG2";
  
  Selfilter "angol", f;#1048;
  run "C:\Program Files\WinRAR\WinRAR.exe" "e" "<curitem>",,1;

  Selfilter "angol", f;#1048;
  moveto ("1");

  Selfilter "720p", f;#1048;
   $count = Get("CountSelected");
   if $count == 1 {
      moveto ("1");
   }
RESULTS:
1
Stargate Universe - 02x06 - Trial and Error.FQM.English.C.orig.Addic7ed.com.srt
Stargate Universe s02e06 (hdtv-fqm) magyar.zip
stargate.universe.s02e06.hdtv.xvid-fqm.avi
stargate.universe.s02e06.hdtv.xvid-fqm.ENG2.srt

Question: How can I select&focus the .srt file NOT ending with .ENG2.srt

(the .srt file has always different basename, so com.srt is not good)
(and the .srt file and .ENG2.srt can have different order)

Re: I need script that mass renames SRTs using AVI file basename

Posted: 06 Nov 2010 18:56
by zer0
xyka wrote:@zer0, Winrar doesn't unrar file if I use your run command

Here is what works:

Code: Select all

  Selfilter "angol", f;#1048;
  run "C:\Program Files\WinRAR\WinRAR.exe" "e" "<curitem>",,1;
Not sure why that works as, per help file, "names with blanks must be quoted. Note that the quotes have to be wrapped in single-quotes because an argument's outer quotes are auto-stripped by XY's script parser!"
xyka wrote:Question: How can I select&focus the .srt file NOT ending with .ENG2.srt

(the .srt file has always different basename, so com.srt is not good)
(and the .srt file and .ENG2.srt can have different order)
What you can do is embed another if loop (like one in step 11) into first part of 9.3.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 08 Nov 2010 01:05
by xyka
zer0 wrote:...
11.

Code: Select all

Selfilter "*.srt", f;
     $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, '|');
      
      if (strpos($name, ".ENG") == -1)
      {
         rename b, $a,,$file;
      }
   }
In case of
D:\MY_VIDEOS\STARGATE UNIVERSE - 2 x 06 - FQM\stargate.universe.s02e06.hdtv.xvid-fqm.ENG.srt
On which one \ does this regexp matches?
^.+\\(.+)$
at the beginning of the line, at least one character, \, (at least one character), at the end of the line
and "$1" means that I get back what was under (.+)

Where does evaluation start, from D:\ or from .srt part?
Which has stronger precedence ^ or $?
I don't understand it clearly.
REGEXP tutorial:

Code: Select all

http://www.zytrax.com/tech/web/regex.htm
^ The ^ (circumflex or caret) outside square brackets means look only at the beginning of the target string.
$ The $ (dollar) means look only at the end of the target string, for example, fox$ will find a match in 'silver fox' since it appears at the end of the string but not in 'the fox jumped over the moon'.
. The . (period) means any character(s) in this position, for example, ton. will find tons and tonneau but not wanton because it has no following character.
+ The + (plus) matches the previous character 1 or more times, for example, tre+ will find tree and tread but not trough.

Re: I need script that mass renames SRTs using AVI file basename

Posted: 08 Nov 2010 10:54
by xyka
I think I've figured it out.
I have tested regexps using N++ notepad.

D:\4\abc123def.srt ==> ^.+\\ ==> D:\4\abc123def.srt
D:\4\abc\123def.srt ==> ^.+\\ ==> D:\4\abc\123def.srt
D:\4\abc\123\def.srt ==> ^.+\\ ==> D:\4\abc\123\def.srt

RESULT: ^.+\\ means
at the beginning of the line, at least one character {it can be \ too}, the last \


D:\4\abc123def.srt ==> \\(.+)$ ==> D:\4\abc123def.srt
D:\4\abc\123def.srt ==> \\(.+)$ ==> D:\4\abc\123def.srt
D:\4\abc\123\def.srt ==> \\(.+)$ ==> D:\4\abc\123\def.srt

RESULT: \\(.+)$
the first \, (at least one character {it can be \ too}), at the end of the line


That is ^.+\\(.+)$
D:\MY_VIDEOS\STARGATE UNIVERSE - 2 x 06 - FQM\stargate.universe.s02e06.hdtv.xvid-fqm.ENG.srt


-