Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Bookmark Directories

Aug
1,916
68
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
 
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".
 
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.
 
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.
 
Steve, I learn something new every day! But honestly, I don't think I've ever needed a case-sensitive comparison.
 
Back
Top