#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    2
    Rep Power
    0

    Finding last token in batch file


    Hey,

    I have a batch file which gets a full path name as an argument. I want just the name of the last folder in that path and this regardless of path depth.

    I've been trying things like this:
    Code:
    for /f "tokens=2* delims=\" %%a in (%1) do echo %%a
    but don't seem to find a way to access only the last token.
    Any ideas?

    thx
    Koen
  2. #2
  3. Who set my Title?
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2004
    Posts
    716
    Rep Power
    258
    try this
    Code:
    for %%a in (%1) do echo %%~nxa
    Nobody is perfect. I am Nobody.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    2
    Rep Power
    0
    Originally Posted by LaughingBelly
    try this
    Code:
    for %%a in (%1) do echo %%~nxa
    That works, thx!!!

IMN logo majestic logo threadwatch logo seochat tools logo