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

Bookmark Directories

Discussion in 'T&T - Scripting' started by Joe Caverly, Jan 2, 2013.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    638
    Likes Received:
    6
    Code:
    ::--------------------------------------------------------------------
    :: BM.BTM
    ::
    :: This batch file displays all environment variables
    ::   that begin with bm, which represent directory bookmarks.
    ::
    :: To bookmark the current directory, usage is;
    ::
    :: BM 1 or BM 2 or BM 3 .... or BM 9
    ::
    :: If a bookmark does not exist for the number, then you will be asked
    ::   if you want to bookmark the current directory.
    ::
    :: If a bookmark exists for the number, then the directory will be
    ::   changed to the bookmarked directory.
    ::
    :: If you want to see the existing bookmarks, usage is;
    ::
    ::   BM
    ::
    :: Joe Caverly - 2013/01/01
    ::--------------------------------------------------------------------
    @setlocal
    @echo off
    ::
    :: If no parameters were passed to this batch file,
    ::   just display the existing bookmarks.
    ::
    iff %# eq 0 then
      ::
      :: Display all environment variables that begin with bm,
      ::   followed by one character
      ::
      set bm?
    else
    ::
    :: Parameters have been passed to this batch file.
    ::
      ::
      :: If the directory that the bookmark points to exists,
      ::
      iff exist %[bm%1] then
        ::
        :: Change to that directory once the batch file is done.
        ::
        defer cd %[bm%1]
      else
        ::
        :: Ask the user if they want to bookmark this directory.
        ::
        set yorn=n
        inkey /C /P /K"yn" Do you want to set bm%1 = %_cwd %%yorn
        iff %@lower[%yorn] eq y defer set bm%1=%_cwd
      endiff
    endiff
    endlocal
     
  2. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Interesting technique... I didn't know that "DEFER SET var=value" can be used to export var's new value outside of a SETLOCAL/ENDLOCAL scope. Another way to export is using "ENDLOCAL bm%1".
     
  3. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Just a small note I'll illustrate by the following:
    Code:
    [Z:\]if a eq a Echo Obviously
    Obviously
     
    [Z:\]if a eq A Echo Case doesn't matter!
    Case doesn't matter!
    
    In TCC string comparisons are not sensitive to case.

    If you actually want case sensitivity, use the @ASCII function as follows:
    Code:
    [Z:\]Set Reply=A
     
    [Z:\]If %@ASCII[%Reply] == %@ASCII[A] Echo Is uppercase.
    Is uppercase.
     
    [Z:\]If %@ASCII[%Reply] == %@ASCII[a] Echo Is Lowercase
     
    [Z:\]Set Reply=a
     
    [Z:\]If %@ASCII[%Reply] == %@ASCII[A] Echo Is uppercase.
     
    [Z:\]If %@ASCII[%Reply] == %@ASCII[a] Echo Is Lowercase
    Is Lowercase
     
    [Z:\]
    
    This even works for multiple characters (if that's really what you want to do):
    Code:
    [Z:\]Set Reply=abcdefg
     
    [Z:\]If %@Ascii[%Reply] == %@Ascii[abcdefg] Echo Is Equal
    Is Equal
     
    [Z:\]If %@Ascii[%Reply] == %@Ascii[aBcdefg] Echo Is Equal
     
    [Z:\]
    
    Just thought that this was worth knowing.
     
  4. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    For case-sensitive string matching, the relational operator EQC is available in TCC (and has been available since 4NT 6):

    test result
    a EQ A true
    a EQC A false

    Please view the table of relational operators in the HELP topic Conditional Expressions, subtopic Relational Operators.
     
  5. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Steve, I learn something new every day! But honestly, I don't think I've ever needed a case-sensitive comparison.
     

Share This Page