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-08-06 06:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can't you add a path in the in? View 2,278 Replies 7
Original Poster Posted 2007-10-16 12:51 ·  中国 广东 东莞 电信
初级用户
★★
Credits 201
Posts 92
Joined 2005-12-28 17:44
20-year member
UID 48072
Status Offline
I learned from the forum that this command is very useful to get the single file name + extension name

for /r %a in (*.*) do @if exist %a echo %~nxa

Encountered the following problems:

1. Can you add a path after in?

Like this: for /r %a in (%CD%\*.*) do @if exist %a echo %~nxa
But it doesn't run

2. If you want to get the complete path name, file and extension name, how to do it?

Like this result:
C:\Windows\notepad.exe
c:\windows\hh.exe

Thanks for the advice
Floor 2 Posted 2007-10-16 12:53 ·  中国 广东 东莞 电信
初级用户
★★
Credits 201
Posts 92
Joined 2005-12-28 17:44
20-year member
UID 48072
Status Offline
For the second point, it can be solved like this. Just not that straightforward.

for /r %a in (*.*) do @if exist %a echo %cd%\%~nxa
Floor 3 Posted 2007-10-16 12:57 ·  中国 广东 东莞 电信
初级用户
★★
Credits 201
Posts 92
Joined 2005-12-28 17:44
20-year member
UID 48072
Status Offline

for /r %a in (*.*) do @if exist %a echo %~nxa*%cd%\%~nxa
Floor 4 Posted 2007-10-16 18:38 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
1. Can the path be added after in?

Generally, put the path after the /R parameter, and the file type in in:
for /R C:\windows %a in (*.exe) do @echo %a


2. If you want to get the complete path name, file and suffix name, how to do it?

Take a look at the help of for!
for /R %a in (*.*) do @echo %~fa
Floor 5 Posted 2007-10-16 19:33 ·  中国 江西 南昌 电信
中级用户
★★
Credits 245
Posts 123
Joined 2007-06-08 09:04
19-year member
UID 90636
Gender Female
Status Offline
Floor 6 Posted 2007-10-20 10:36 ·  中国 广东 东莞 电信
初级用户
★★
Credits 201
Posts 92
Joined 2005-12-28 17:44
20-year member
UID 48072
Status Offline
Generally, the path is placed after the /R parameter, and the file type is placed in in:

--------------------------------------------------------------------------------

for /R C:\windows %a in (*.exe) do @echo %a




--There is a problem. This will enumerate the directories under this directory, including subdirectories. How to only specify this directory without including its subdirectories?
Floor 7 Posted 2007-10-20 14:14 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Refer to for /D.

[ Last edited by lxmxn on 2007-10-20 at 02:15 PM ]
Floor 8 Posted 2007-10-23 13:47 ·  中国 广东 东莞 电信
初级用户
★★
Credits 201
Posts 92
Joined 2005-12-28 17:44
20-year member
UID 48072
Status Offline
Originally posted by lxmxn at 2007-10-20 14:14:
Refer to for /D.

[ Last edited by lxmxn on 2007-10-20 at 02:15 PM ]


Thank you very much...
Forum Jump: