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-27 06:16
中国DOS联盟论坛 » 其它操作系统综合讨论区 » [fixed] How to use a command to specify the path of identically named files under different usernames? View 1,224 Replies 9
Original Poster Posted 2007-08-20 10:42 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 113
Posts 51
Joined 2007-02-15 22:54
19-year member
UID 79590
Gender Male
Status Offline
Floor 2 Posted 2007-08-20 11:32 ·  中国 北京 鹏博士BGP
初级用户
Credits 71
Posts 30
Joined 2006-12-14 08:42
19-year member
UID 73492
Gender Male
Status Offline
Floor 3 Posted 2007-08-20 14:32 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Use the for command to extract the output of the following command:

dir "c:\Documents and Settings" /b /d
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 4 Posted 2007-08-20 16:03 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 113
Posts 51
Joined 2007-02-15 22:54
19-year member
UID 79590
Gender Male
Status Offline
Thanks, using dir "c:\Documents and Settings" /b /d I can already get the usernames, but how do I use the for command to extract the output of the following command? I tried several times and still couldn't do it. Climbing and all experts, please help again, many thanks!

[ Last edited by superadam on 2007-8-20 at 04:05 PM ]
Floor 5 Posted 2007-08-20 17:43 ·  中国 广东 广州 白云区 电信
初级用户
Credits 25
Posts 11
Joined 2007-05-18 00:40
19-year member
UID 88882
Gender Male
Status Offline
Just passing by`

[ Last edited by itolaiai on 2007-8-21 at 05:05 PM ]
Floor 6 Posted 2007-08-21 08:19 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Basically as the poster above wrote, you can also do it like this:

for /f "usebackq delims=" %i in (`dir /b/d "c:\documents and settings"`) do xcopy /e/i "c:\documents and settings\%i\Favorites" "x:\target"

x:\target means the target directory.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
superadam +2 2007-08-21 09:24
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2007-08-21 08:50 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 113
Posts 51
Joined 2007-02-15 22:54
19-year member
UID 79590
Gender Male
Status Offline
Originally posted by Climbing at 2007-8-21 08:19 AM:
Basically as the poster above wrote, you can also do it like this:

for /f "usebackq delims=" %i in (`dir /b/d "c:\documents and settings"`) do xcopy /e/i "c:\documents and settings\%i\Favori ...


The answer I'm adopting now is as follows:
for /f "usebackq delims=" %i in (`dir /b/d "c:\documents and settings"`) do xcopy /e/i "c:\documents and settings\%i\Favorites" "x:\target"

x:\target means the target directory.

Many thanks to the two posters above for the replies. After using Climbin's method, the problem has been completely solved. But I still have one more question now. May I continue to ask Climbin something? What's the difference in syntax between "usebackq delims=" and "delims="? How should it be explained?

[ Last edited by superadam on 2007-8-21 at 09:31 AM ]
Floor 8 Posted 2007-08-21 09:31 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
This is how I understand usebackq: use backquotes (`) to enclose the command sequence that will be executed. Under normal circumstances, single quotes (') are used to enclose the command, but sometimes the command arguments need single quotes or double quotes as well (and then it causes confusion between single and double quotes). In that case it's best to use the usebackq parameter, and then use backquotes to enclose the command, so this kind of trouble won't happen.

As for the "delims=" parameter, it is used to specify the string delimiter. The for /f command is mainly used to extract fields from a string. Since there is a distinction between fields, there must be symbols to separate the fields. By default it is space or Tab. You can use delims= to specify the delimiter you want to use, and in this example, of course you do not want to use any delimiter, so delims= is specified as empty.

For this, you can just check Microsoft's for /?. Although its explanation feels rather confusing, after enough time you'll naturally understand it.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 9 Posted 2007-08-21 09:32 ·  中国 福建 厦门 思明区 电信
初级用户
★★
Credits 156
Posts 76
Joined 2007-08-20 11:52
19-year member
UID 95399
Gender Male
Status Offline
Run cmd and enter for /? and you should see something.
Floor 10 Posted 2007-08-21 09:33 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 113
Posts 51
Joined 2007-02-15 22:54
19-year member
UID 79590
Gender Male
Status Offline
Alright, I'll look at the syntax first. If there's anything I don't understand, I'll ask you again~~
Thanks, Climbing, for taking your valuable time to reply. Your reply was really timely, thanks. The problem has been successfully solved. Really, really many thanks!
This thread can be closed now. Please have a moderator close it for me, thanks~~:D

[ Last edited by superadam on 2007-8-21 at 09:35 AM ]
Forum Jump: