China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:49
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » May I ask: How to get the current directory name? (Solved) View 2,680 Replies 6
Original Poster Posted 2007-03-15 04:08 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Current directory is:
C:\Documents and Settings\Administrator\Desktop\test
Double-clicking the batch file needs to get test

For example: C:\Documents and Settings\Administrator\Desktop\test1
Double-clicking the batch file needs to get test1

Please everyone actively and enthusiastically answer ;)

Thank you all ;) (Here "Japanese people" are not welcome! Hehe)

[ Last edited by huzixuan on 2007-3-15 at 06:57 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
jivejiang -1 2010-06-14 10:49
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 2 Posted 2007-03-15 04:10 ·  中国 重庆 沙坪坝区 电信
中级用户
★★
金牌会员
Credits 315
Posts 152
Joined 2007-01-25 23:55
19-year member
UID 77669
Gender Male
Status Offline
Yoshi

[ Last edited by fengzi on 2007-3-14 at 03:11 PM ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
huzixuan -1 2007-03-15 04:14
youxi01 -4 2007-03-15 06:09
zhoushijay -3 2007-03-15 07:03
dslz666 -2 2008-05-16 13:21
Floor 3 Posted 2007-03-15 05:35 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
@echo off
for /f "tokens=5 delims=\" %%i in ('cd') do echo %%i
pause


[ Last edited by ccwan on 2007-3-15 at 07:27 AM ]
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 4 Posted 2007-03-15 05:37 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
```
@echo off
call :str "%cd%"
pause
exit

:str
echo %~n1
goto :eof
```

[ Last edited by zh159 on 2007-3-14 at 04:38 PM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
youxi01 +4 2007-03-15 06:12
huzixuan +4 2007-03-15 06:57
Floor 5 Posted 2007-03-15 07:00 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Brother zh159, your use of "call" is quite clever!
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 6 Posted 2007-03-15 08:26 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Thanks for the correction from the 7th floor. It has been modified, please test...

@echo off
for /f "delims=" %%i in ("%cd%") do (
if %%i EQU %%~di\ (
echo %%~di
) else (
echo %%~ni
)
)
pause>nul


[ Last edited by jmz573515 on 2007-3-14 at 10:23 PM ]
Floor 7 Posted 2007-03-15 10:48 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
Originally posted by zh159 at 2007-3-14 16:37:
@echo off
call :str "%cd%"
pause
exit

:str
echo %~n1
goto :eof


[ Last edited by zh159 on 2007-3-14 at 04:38 PM ]


Test:

F:\zdrq>test
zdrq
Press any key to continue. . .
ECHO is off.

And it and the one on floor 6, if in the X:\ root directory, both don't work!
ECHO is on.


[ Last edited by xycoordinate on 2007-3-15 at 08:19 AM ]
Forum Jump: