Is there any way of doing this?
thank you
NT4/2K/XP/2K3 (NT+ systems) are discussed in alt.msdos.batch.nt as the
techniques used differ markedly from DOS/9x methods.
You appear to be posting from XP, so this should work for you
----- batch begins -------
[1]@echo off
[2]set ts_x=d:\folder1\folder2\folder3
[3]:: method 1
[4]for /f %%i in ("%ts_x%") do set ts_y=%%~dpi
[5]set ts_y=%ts_y:~0,-1%
[6]set ts
[7]:: method 2
[8]setlocal enabledelayedexpansion
[9]for /f %%i in ("%ts_x%") do set ts_y=%%~dpi&set ts_y=!ts_y:~0,-1!
[10]set ts
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
%varname% will be evaluated as the value of VARNAME at the time that the
line is PARSED. The ENABLEDELAYEDEXPANSION option to SETLOCAL causes
!varname! to be evaluated as the CURRENT value of VARNAME - that is, as
modified by the operation of the FOR
[4..5] and [8..9] are different methods to do the same thing.
[6,10] simply show the results
YMMV if you use spaces or other special characters in your names. The trick
is to treat the name as a filename and extract the resultant drive and
directory name using the ~operator; then remove the terminal "\"
see
SETLOCAL /?
FOR /?
SET /?
from the prompt for more complete documentation - or alt.msdos.batch.nt for
examples....
>Hello
>I have an environment variable named something linke
>TS_X=d:\folder1\folder2\folder3
>I would like to have in another variable d:\folder1\folder2
In NT versions of Windows:
@echo off
set "TS_X=d:\folder1\folder2\folder3"
for %%a in ("%ts_x%") do set "TS_Y=%%~dpa"
Since you seem to post from an NT-system, the more appropriate newsgroup
for this is alt.msdos.batch.nt (included and followups redirected).
As to the problem, adapted from a concomitant
80} How can I extract the last part of a path such as C:\ABC\DEF\GHI\?
202569 Dec 23 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Http link format http://garbo.uwasa.fi/pub/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
@echo off & setlocal enableextensions
set TS_X=d:\folder1\folder2\folder3
echo %TS_X%
for %%a in ("%TS_X%") do echo %%~dpa
endlocal & goto :EOF
Output:
C:\_D\TEST>cmdfaq
d:\folder1\folder2\folder3
d:\folder1\folder2\
For more, see the said item and FAQ.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FI-65101, Finland
Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip
black...@gmail.com wrote:
>Hello