|
blogsss
初级用户
 
积分 36
发帖 14
注册 2007-6-28
状态 离线
|
『楼 主』:
[求助]for结果集中字符串截取问题,一定给分!
使用 LLM 解释/回答一下
for /f "delims=" %i in ('dir download /b/s') do @echo %i
结果如下
c:\download\1.txt
c:\download\aaa\2.txt
问题是要在结果集中把 c:\download\去掉, 该怎么办呢? 多谢,一定给分,虽然只能给2分!
Last edited by blogsss on 2007-6-30 at 01:49 PM ]
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 ]
|
|
2007-6-30 12:50 |
|
|
qingfushuan
高级用户
   
积分 502
发帖 327
注册 2006-12-30
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /? 最后几句
另外,FOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:
~I - 删除任何引号("),扩充 %I
%~fI - 将 %I 扩充到一个完全合格的路径名
%~dI - 仅将 %I 扩充到一个驱动器号
%~pI - 仅将 %I 扩充到一个路径
%~nI - 仅将 %I 扩充到一个文件名
%~xI - 仅将 %I 扩充到一个文件扩展名
%~sI - 扩充的路径只含有短名
%~aI - 将 %I 扩充到文件的文件属性
%~tI - 将 %I 扩充到文件的日期/时间
%~zI - 将 %I 扩充到文件的大小
%~$PATH:I - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个完全合格的名称。如果环境变量名
未被定义,或者没有找到文件,此组合键会扩充到
空字符串
可以组合修饰符来得到多重结果:
%~dpI - 仅将 %I 扩充到一个驱动器号和路径
%~nxI - 仅将 %I 扩充到一个文件名和扩展名
%~fsI - 仅将 %I 扩充到一个带有短名的完整路径名
%~dp$PATH:i - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个驱动器号和路径。
%~ftzaI - 将 %I 扩充到类似输出线路的 DIR
在以上例子中,%I 和 PATH 可用其他有效数值代替。%~ 语法
用一个有效的 FOR 变量名终止。选取类似 %I 的大写变量名
比较易读,而且避免与不分大小写的组合键混淆。
上面的 "%~nxI - 仅将 %I 扩充到一个文件名和扩展名"就是啊
Last edited by qingfushuan on 2007-6-30 at 01:33 PM ]
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 ]
|
|
2007-6-30 13:10 |
|
|
blogsss
初级用户
 
积分 36
发帖 14
注册 2007-6-28
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
what ?
是我没说清楚吗?
what ?
Is it that I didn't make myself clear?
|
|
2007-6-30 13:19 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
呀。奇怪了。dir /b后应该不存在这个问题的。
偶测试楼主的,不存在这样的问题。
另外2楼说的是这个
另外,FOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:
~I - 删除任何引号("),扩充 %I
%~fI - 将 %I 扩充到一个完全合格的路径名
%~dI - 仅将 %I 扩充到一个驱动器号
%~pI - 仅将 %I 扩充到一个路径
%~nI - 仅将 %I 扩充到一个文件名
%~xI - 仅将 %I 扩充到一个文件扩展名
%~sI - 扩充的路径只含有短名
%~aI - 将 %I 扩充到文件的文件属性
%~tI - 将 %I 扩充到文件的日期/时间
%~zI - 将 %I 扩充到文件的大小
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
|
|
2007-6-30 13:36 |
|
|
qinbuer
高级用户
    我思故我在
积分 512
发帖 228
注册 2007-1-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
如果c:\download\是确定的,直接截取字符串不可以吗?
Last edited by qinbuer on 2007-6-30 at 01:45 PM ]
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他。 |
|
2007-6-30 13:43 |
|
|
blogsss
初级用户
 
积分 36
发帖 14
注册 2007-6-28
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
原来的代码有点小问题啦,就是 dir /b 少了/s, 已经改过来了,但不是主要问题,我想要的是在结果集中去掉一部分前边的目录,在上例中是
c:\download\1.txt
c:\download\aaa\2.txt
去掉 c:\download\, 该怎么办呢? 多谢,一定给分,虽然只能给2分!
使用%~转换参数只能保留文件名或扩展到全路径什么的,好像不能实现上面的要求!
另外delims好像不支持字符串,那要如何直接截取字符串呢?
不管怎么说,还是谢谢各位了,盼望高人出现。。。
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...
|
|
2007-6-30 13:57 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
%~nxi不行吗?
楼主是说delims=c:\download\
如楼主所说。aaa\2.txt这样的格式也需要?
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?
|
|
2007-6-30 14:05 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %i in ('dir download /b/s') do @echo %~nxi
for /f "delims=" %i in ('dir download /b/s') do @echo %~nxi
|
|
2007-6-30 14:06 |
|
|
wjh6088
初级用户
 
积分 85
发帖 39
注册 2007-6-28
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
for /f "tokens=1,2,3* delims=\" %i in ('dir download /b/s') do @echo %k
对于 `for /f "tokens=1,2,3* delims=\" %i in ('dir download /b/s') do @echo %k`
|
|
2007-6-30 14:09 |
|
|
blogsss
初级用户
 
积分 36
发帖 14
注册 2007-6-28
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by wudixin96 at 2007-6-30 02:05 PM:
%~nxi不行吗?
楼主是说delims=c:\download\
如楼主所说。aaa\2.txt这样的格式也需要?
就是这个意思
8,9楼好像都不行哦,正确的输出结果应该是
1.txt
aaa\2.txt
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
|
|
2007-6-30 14:23 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
for /f "tokens=2* delims=\" %i in ('dir download /a-d /b /s') do @echo %j
这样?
for /f "tokens=2* delims=\" %i in ('dir download /a-d /b /s') do @echo %j
Is this so?
|
|
2007-6-30 14:32 |
|
|
wjh6088
初级用户
 
积分 85
发帖 39
注册 2007-6-28
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
for /f "tokens=1,2,* delims=\" %i in ('dir c:\download /a-d/b/s') do @echo %k
for /f "tokens=1,2,* delims=\" %i in ('dir c:\download /a-d/b/s') do @echo %k
|
|
2007-6-30 14:33 |
|
|
blogsss
初级用户
 
积分 36
发帖 14
注册 2007-6-28
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
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
这样?
高手,同样喜欢你的头像,今天不能评分了,明天一定给!
Last edited by blogsss on 2007-6-30 at 02:41 PM ]
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 ]
|
|
2007-6-30 14:40 |
|
|
qinbuer
高级用户
    我思故我在
积分 512
发帖 228
注册 2007-1-21
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
@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
那岂不是这样也可以?
Last edited by qinbuer on 2007-6-30 at 02:48 PM ]
@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他。 |
|
2007-6-30 14:46 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
楼上看清楚哦。是在cmd里哦。
不是P文件里。
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.
|
|
2007-6-30 14:54 |
|