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-05 06:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] String Interception Problem in For Result Set, Definitely Give Points! View 1,916 Replies 16
Original Poster Posted 2007-06-30 12:50 ·  中国 北京 联通
初级用户
Credits 36
Posts 14
Joined 2007-06-28 16:09
19-year member
UID 92592
Gender Male
Status Offline
for /f "delims=" %i in ('dir download /b/s') do @echo %i:~11

The result is as follows
c:\download\1.txt
c:\download\aaa\2.txt

The problem is to remove c:\download\ from the result set, how to do it? Thank you, will definitely give points, although only 2 points can be given!

[ Last edited by blogsss on 2007-6-30 at 01:49 PM ]
Floor 2 Posted 2007-06-30 13:10 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
In addition, the replacement of FOR variable references has been enhanced. You can now use the following option syntax:

~I - Remove any quotation marks ("), expand %I
%~fI - Expand %I to a fully qualified pathname
%~dI - Expand %I to only a drive letter
%~pI - Expand %I to only a path
%~nI - Expand %I to only a file name
%~xI - Expand %I to only a file extension
%~sI - The expanded path contains only the short name
%~aI - Expand %I to the file attributes of the file
%~tI - Expand %I to the date/time of the file
%~zI - Expand %I to the size of the file
%~$PATH:I - Find the directory listed in the path environment variable and expand %I to the first found fully qualified name. If the environment variable name is not defined or the file is not found, this combination key will expand to an empty string

You can combine modifiers to get multiple results:

%~dpI - Expand %I to only a drive letter and path
%~nxI - Expand %I to only a file name and extension
%~fsI - Expand %I to a complete pathname with a short name
%~dp$PATH:i - Find the directory listed in the path environment variable and expand %I to the first found drive letter and path.
%~ftzaI - Expand %I to a DIR-like output line

In the above examples, %I and PATH can be replaced with other valid values. The %~ syntax ends with a valid FOR variable name. Choosing a capital variable name like %I is easier to read and avoids confusion with case-insensitive combination keys.


The above "%~nxI - Expand %I to only a file name and extension" is it

[ Last edited by qingfushuan on 2007-6-30 at 01:33 PM ]
Floor 3 Posted 2007-06-30 13:19 ·  中国 北京 联通
初级用户
Credits 36
Posts 14
Joined 2007-06-28 16:09
19-year member
UID 92592
Gender Male
Status Offline
what ?

Is it that I didn't make myself clear?
Floor 4 Posted 2007-06-30 13:36 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Ya. It's strange. There should be no such problem after dir /b.
I tested the owner's, and there is no such problem.

In addition, what the 2nd floor said is this

In addition, the replacement of FOR variable references has been enhanced. You can now use the following
option syntax:

~I - Remove any quotes ("), expand %I
%~fI - Expand %I to a fully qualified pathname
%~dI - Expand %I to only a drive letter
%~pI - Expand %I to only a path
%~nI - Expand %I to only a file name
%~xI - Expand %I to only a file extension
%~sI - The expanded path contains only short names
%~aI - Expand %I to the file attributes of the file
%~tI - Expand %I to the date/time of the file
%~zI - Expand %I to the size of the file
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
blogsss +1 2007-06-30 13:57
Floor 5 Posted 2007-06-30 13:43 ·  中国 广东 佛山 电信
高级用户
★★
我思故我在
Credits 512
Posts 228
Joined 2007-01-21 10:31
19-year member
UID 77225
Gender Male
Status Offline
If c:\download\ is definite, can we just intercept the string directly?

[ Last edited by qinbuer on 2007-6-30 at 01:45 PM ]
我确实是只菜鸟,而且这里X人太多,所以我不敢装X。谁要再说我装X,我就XXOO他。
Floor 6 Posted 2007-06-30 13:57 ·  中国 北京 联通
初级用户
Credits 36
Posts 14
Joined 2007-06-28 16:09
19-year member
UID 92592
Gender Male
Status Offline
The original code had a small issue, that is, dir /b was missing /s, which has been corrected, but that's not the main problem. What I want is to remove a part of the preceding directory from the result set. In the previous example, it's

c:\download\1.txt
c:\download\aaa\2.txt

Remove c:\download\, how to do it? Thanks, I will definitely give points, although I can only give 2 points!

Using %~ to convert parameters can only keep the file name or expand to the full path and so on, it seems that it can't achieve the above requirement!

In addition, delims doesn't support strings, then how to directly intercept strings?

Anyway, thank you all, looking forward to the appearance of experts...
Floor 7 Posted 2007-06-30 14:05 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Can't %~nxi work?

The LZ is saying delims=c:\download\

As the LZ said. Does the format like aaa\2.txt also need it?
Floor 8 Posted 2007-06-30 14:06 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
for /f "delims=" %i in ('dir download /b/s') do @echo %~nxi
Floor 9 Posted 2007-06-30 14:09 ·  中国 广西 南宁 电信
初级用户
Credits 85
Posts 39
Joined 2007-06-28 22:22
19-year member
UID 92624
Gender Male
Status Offline
对于 `for /f "tokens=1,2,3* delims=\" %i in ('dir download /b/s') do @echo %k`
Floor 10 Posted 2007-06-30 14:23 ·  中国 北京 联通
初级用户
Credits 36
Posts 14
Joined 2007-06-28 16:09
19-year member
UID 92592
Gender Male
Status Offline
Originally posted by wudixin96 at 2007-6-30 02:05 PM:
Does %~nxi not work?

The LZ is talking about delims=c:\download\

As the LZ said. Formats like aaa\2.txt are also needed?

That's the meaning.

It seems that neither the 8th nor 9th floor works. The correct output result should be

1.txt
aaa\2.txt
Floor 11 Posted 2007-06-30 14:32 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
for /f "tokens=2* delims=\" %i in ('dir download /a-d /b /s') do @echo %j


Is this so?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
blogsss +2 2007-07-01 13:35
Floor 12 Posted 2007-06-30 14:33 ·  中国 广西 南宁 电信
初级用户
Credits 85
Posts 39
Joined 2007-06-28 22:22
19-year member
UID 92624
Gender Male
Status Offline
for /f "tokens=1,2,* delims=\" %i in ('dir c:\download /a-d/b/s') do @echo %k
Floor 13 Posted 2007-06-30 14:40 ·  中国 北京 联通
初级用户
Credits 36
Posts 14
Joined 2007-06-28 16:09
19-year member
UID 92592
Gender Male
Status Offline
Originally posted by wudixin96 at 2007-6-30 02:32 PM:
for /f "tokens=2* delims=\" %i in ('dir download /a-d /b /s') do @echo %j


Is this like this?


Expert, I also like your avatar. I can't rate today, but I will definitely give it tomorrow!

[ Last edited by blogsss on 2007-6-30 at 02:41 PM ]
Floor 14 Posted 2007-06-30 14:46 ·  中国 广东 佛山 电信
高级用户
★★
我思故我在
Credits 512
Posts 228
Joined 2007-01-21 10:31
19-year member
UID 77225
Gender Male
Status Offline
@echo off & setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in ('dir /a-d /b /s download') do set var=%%i & @echo !var:C:\download=!
pause>nul
Is that so possible too?

[ Last edited by qinbuer on 2007-6-30 at 02:48 PM ]
我确实是只菜鸟,而且这里X人太多,所以我不敢装X。谁要再说我装X,我就XXOO他。
Floor 15 Posted 2007-06-30 14:54 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Please clarify the specific content that needs to be translated. You only provided these two sentences, please provide the full text that needs to be translated.
Forum Jump: