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 08:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Challenge 1] Extract the last name in the directory [Difficulty: ☆] View 3,760 Replies 31
Floor 16 Posted 2007-05-01 02:15 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Originally posted by notepad at 2007-4-30 01:01 PM:
It doesn't work啊 `````

What does it mean???
知,不觉多。不知,乃求知
Floor 17 Posted 2007-05-01 04:37 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
@echo off
for /f "tokens=* delims=" %%i in ('cd') do (
set "fdname=%%i"
call :GetFdName "%fdname%"
)
:GetFdName
for /f "tokens=1,* delims=\" %%j in ("%~1") do (
if "%%k"=="" echo %%j&&pause&&goto :eof
call :GetFdName %%k
)

I made a change. I want it to display the current directory folder name, but why can't fdname be passed to getfdname? If I directly pass %%i, it doesn't display completely when there are spaces in the file, so I need to set fdname to pass to getfdname
Floor 18 Posted 2007-05-01 05:50 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
It's almost May Day. Wish everyone a happy holiday. By the way, people who come here, help me take a look at the problem. Thanks.
Floor 19 Posted 2007-05-01 05:57 ·  中国 新疆 乌鲁木齐 天山区 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
@echo off
for /f "delims=" %%i in ("c:\aa\bb\cc") do (
echo %%~nxi
)
pause
Floor 20 Posted 2007-05-01 06:10 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Originally posted by zhoushijay at 2007-4-30 04:57 PM:
@echo off
for /f "delims=" %%i in ("c:\aa\bb\cc") do (
echo %%~nxi
)
pause


This is my fault for not thinking carefully enough earlier. I forgot to write it down when posting...

The special parameters of for are used...

Our requirement is not to use these special parameters.
知,不觉多。不知,乃求知
Floor 21 Posted 2007-05-01 13:24 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Is there really no one using VBS?
Floor 22 Posted 2007-05-01 16:24 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
```
Set WshSHell = WScript.CreateObject("WScript.Shell")
FP="c:\aaa\bbb\ccc"
FPArr=split(FP,"\")
For i=1 To UBound(FPArr)
FPTest = FPArr(i)
Next
WshSHell.popup "Final directory: " & vbcrlf & FPTest
Set WshSHell = Nothing
WScript.Quit(0)
```
Floor 23 Posted 2007-05-01 16:43 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Set WshSHell = WScript.CreateObject("WScript.Shell")
FP="c:\aaa\bbb\ccc"
FPArr=Split(FP,"\")
For i=1 To UBound(FPArr)
FPTest = FPArr(i)
Next
WshSHell.popup "Final directory: "&vbcrlf&FPTest
Set WshSHell = Nothing
WScript.Quit(0)


MsgBox FPArr(UBound(FPArr)) isn't okay?
InstrRev() isn't okay?


FP = "c:\aaa\bbb\ccc"
FPArr = Split(FP, "\")
MsgBox FPArr(UBound(FPArr))
Pos=InstrRev(FP, "\")+1
MsgBox Mid(FP,Pos,(Len(FP) - InstrRev(FP, "\")))

[ Last edited by slore on 2007-5-1 at 03:56 AM ]
Floor 24 Posted 2007-05-01 17:04 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Can't it be?
Can't it?
Do you still want FP or FPArr?
Floor 25 Posted 2007-05-01 17:06 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
What is the meaning of your loop?
Floor 26 Posted 2007-05-01 17:40 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Using it here is indeed meaningless, but if we investigate it, even the existence of FP has no meaning
Floor 27 Posted 2007-05-01 18:10 ·  中国 浙江 温州 电信
中级用户
★★
Credits 458
Posts 196
Joined 2006-10-05 12:04
19-year member
UID 64614
Status Offline
Use the split function in VBS to split the string by "/" and then use the len function to check each line one by one
Floor 28 Posted 2007-05-08 09:28 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline

@echo off
for /f "tokens=* delims=" %%i in ('cd') do (
set "fdname=%%i"
call :GetFdName %fdname%
)
:GetFdName
for /f "tokens=1,* delims=\" %%j in ("%~1") do (
if "%%k"=="" echo %%j&&pause&&goto :eof
call :GetFdName %%k
)

I modified it. I want it to display the current directory folder name. Why can't fdname be passed to getfdname? If I directly pass %%i, when there are spaces in the file, it won't display completely. So I want to set fdname to pass to getfdname.



The problem before the May 1st holiday, still hope to know the reason, or tell me how to solve the method of displaying file names with spaces, as in the following example, when displaying the current directory name, if the directory name contains spaces, it will not display completely.

@echo off
for /f "tokens=* delims=" %%i in ('cd') do (
call :GetFdName %%i
)
:GetFdName
for /f "tokens=1,* delims=\" %%j in ("%~1") do (
if "%%k"=="" echo %%j&&pause&&goto :eof
call :GetFdName %%k
)


[ Last edited by lililulula on 2007-5-8 at 11:13 AM ]
Floor 29 Posted 2008-04-07 16:40 ·  中国 甘肃 兰州 电信
初级用户
Credits 47
Posts 31
Joined 2008-03-17 19:04
18-year member
UID 113236
Gender Male
Status Offline
Cheer up for your efforts!!
To be honest, raising some meaningful questions and then having everyone discuss and solve them indeed helps to increase the forum's popularity and also helps some newcomers to grow up quickly! Of course, I am also a newcomer, and I am studying hard...
Cheer up for your efforts!!
Floor 30 Posted 2008-04-08 05:38 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
It seems that this issue was discussed a long time ago
Forum Jump: