Re: Extracting last Folder Name from complete path

From: Tom Lavedas (tlavedas_at_hotmail.remove.com)
Date: 12/02/04


Date: Thu, 2 Dec 2004 05:29:06 -0800

The command processor provides file name parsing directly in the FOR ...

 @echo off
  set pfad=D:\Arbeit\PROJEKTE\ATARI 2
  for %%a in ("%PFAD%") do echo %%~na

Type FOR/? at a command prompt for more info and other parsing options.

Tom Lavedas
===========

"andreas kässens" wrote:

> "Michael Bednarek" wrote
>
> > Using 4NT/4DOS, I do this frequently thus:
> > ECHO %@WORD["\",-0,C:\temp\ExtendedDB]
> >
> > 4NT is a commercial product, 4DOS is free
>
> Thanks a lot for your answer! But I have to use the standard Windows xp
> commands, which do not have such function. So I tried the following batch:
>
> @echo off
> set pfad=D:\Arbeit\PROJEKTE\ATARI 2
> for /f "delims=\ tokens=4" %%a in ("@echo %pfad%") do @echo %%a
>
> Unfortunately there seems to be no way to address the last token in general
> ("tokens=-1" does not work). The only way I can think of, is another for
> loop, which counts the "\" in the variing path and replace it with the
> tokens value.
>
> This seems to be far too much effort for such a simple task, doesn't it?
>
> Andreas
>
>
>



Relevant Pages

  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... I open several Command windows in succession. ... Drag the name of C000_CreateSymbols.bat into a new command window ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)