1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

See if a file name matches extended range.

Discussion in 'Support' started by Charles G, Jul 24, 2017.

  1. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    How would I see if a file matches:

    "*.jpgMA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9].[0-9][0-9][0-9]"

    Looked at @wild but that does not fit... Thank you!
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    Are you testing if a given name is valid or if it exists?
     
  3. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    for %fn in (*) if %fn matches "*.jpgMA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9].[0-9][0-9][0-9]" move "%fn" destination....
     
  4. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    I could use @right[3,%fn] and see if that is a number, then test other substrings to see if they match the pattern but I'd rather do one test - one function call...
     
  5. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    Can't you change the grouping instead?
    Code:
    do fn in *.jpgMA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9].[0-9][0-9][0-9] (move "%fn" destination....)
    
     
  6. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    Look at the peseucode for the otherwise part of the switch statement in [:SelectPathForType] in the attached BTM...
     

    Attached Files:

  7. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    You could use @REGEX.
    Code:
    if %@REGEX[".*\.jpgMA\d\d\d\d\d\d\d\d_\d\d\d\.\d\d\d",%sName] == 1 set sTargetSubDir=My Images
    
     
  8. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    I know TCC/TCMD has a regex analysier / tester - but any documentation on constructing one?

    Also thank you very much @samintz
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    The expression I posted matches your wildcard filename. But if you want to play with regular expressions use the regex dialog. Ctrl+F7 or REGEX at the prompt.
    upload_2017-7-24_16-51-54.png
     
  10. rps

    rps

    Joined:
    Jul 6, 2008
    Messages:
    202
    Likes Received:
    3
    Open the Tcmd/TCC Help file
    search for "@regex"
    under the @regex help there is a link to "Regular Expression Syntax"
    .OR.
    search for regular expression syntax
    scroll down in the Select topic: window and choose Take Command/TCC Regular Express....

    When I do this search the 6th topic is what I am looking for. I added this to my Favorites tab for future reference.

    This should assist you in constructing a regular expression.

    You could also try: "\w\.jpgMA\d{8}_\d{3}\.\d{3}" assuming the name before the 1st '.' has no special characters. The numbers are inside curly brackets.

    There are obviously other ways to construct a Regex that only requires the filename with any combo of digits before and/or after the underscore "_". But based on what I understand from the OP the above should work.
     
  11. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
  12. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    Looking over the CHM reg exp help - I don't see a way to test if the MA are both uppercase?
     
  13. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Regex defaults to case sensitive unless you wrap it in a group and add the ignore case option.
    Code:
    \w\.jpg(?i:MA)\d{8}_\d{3}\.\d{3}
    Edit: See 7. Extended groups in the Regular Expression Syntax of the help file.

    Edit 2: You can also precede the specific section (or entire expression) with the option to apply it to all following text without enclosing the desired text within the group. You can then turn ignore case off again.
    Code:
    \w\.jpg(?i)MA\d{8}_\d{3}\.\d{3}
    \w\.jpg(?i)MA(?-i)\d{8}_\d{3}\.\d{3}
     
    #13 JohnQSmith, Jul 27, 2017
    Last edited: Jul 27, 2017
  14. rps

    rps

    Joined:
    Jul 6, 2008
    Messages:
    202
    Likes Received:
    3
    The way the Regex is currently written means MA is uppercase.
    Did you try using lower case letters, say Ma, is your file name. If you do the current Regex shouldn't match foo.jpgMa..... since the expression is specific to MA, all caps.

    If you need to match MA, Ma, ma, or mA then add (?i), meaning case insensitive, to the Regx before the MA string.
    Example: Regex \w\.jpg(?i)ma\d{8}_\d{3}\.\d{3} will match foo.jpgmA12345678_123.123

    BTW, this was not in the TCC syntax docs. Found this info on-line somewhere. :happy:

    Ah! didn't see that until JohnQSmith pointed it out. Thanks.
     
  15. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,941
    Likes Received:
    30
    In addition to extended groups, you can turn case-insensitivity on (with "(?i)") and off (with "(?-i)"). The two may be equivalent, and the extended group is a tad easier.
    upload_2017-7-27_13-37-0.png
     
  16. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,941
    Likes Received:
    30
    "REGEX at the prompt" ... ?
     

Share This Page