Thread: Batch file checking current directory name

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130

    Batch file checking current directory name

    I have a batch file (actually any simple script for Win7 will do, but it already is a cmd file and I would like to keep it that way) that I would like to run only if the directory it is run from has a specific name.

    In my case, it creates an "externals" folder and integrates with SVN, but I would like to stop running if the current directory is not named "trunk". There is a warning message to only start it from the "trunk" folder of a new project... but you know how people are.

    Through a lot of googling I found that the current path is %cd% and I know how to check a string for equality. I also found a hack to check if a string contains something. But what I would like to know is if my string ends in "\trunk". Any ideas or pointers?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Found it. For anyone interested:

    @if not "%cd:~-6%"=="\trunk" goto not_trunk


    Jeez. I really need a shower after programming this piece of...
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-30-2010, 06:13 PM
  2. How to get the current directory and the file name
    By megareix in forum Windows Programming
    Replies: 6
    Last Post: 01-08-2009, 10:01 PM
  3. How to store file in current directory
    By jk1998 in forum C++ Programming
    Replies: 2
    Last Post: 05-11-2007, 02:18 PM
  4. getting current directory
    By Corrington_j in forum Linux Programming
    Replies: 2
    Last Post: 09-07-2005, 10:04 PM
  5. Current Directory
    By xds4lx in forum Windows Programming
    Replies: 4
    Last Post: 11-13-2002, 11:45 PM