![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-05 05:31 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] String Interception Problem in For Result Set, Definitely Give Points! |
| Printable Version 1,913 / 16 |
| Floor1 blogsss | Posted 2007-06-30 12:50 |
| 初级用户 Posts 14 Credits 36 | |
|
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 ] |
|
| Floor2 qingfushuan | Posted 2007-06-30 13:10 |
| 高级用户 Posts 327 Credits 502 | |
|
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 ] |
|
| Floor3 blogsss | Posted 2007-06-30 13:19 |
| 初级用户 Posts 14 Credits 36 | |
|
what ?
Is it that I didn't make myself clear? |
|
| Floor4 wudixin96 | Posted 2007-06-30 13:36 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
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 |
|
| Floor5 qinbuer | Posted 2007-06-30 13:43 |
| 高级用户 Posts 228 Credits 512 | |
|
If c:\download\ is definite, can we just intercept the string directly?
[ Last edited by qinbuer on 2007-6-30 at 01:45 PM ] |
|
| Floor6 blogsss | Posted 2007-06-30 13:57 |
| 初级用户 Posts 14 Credits 36 | |
|
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... |
|
| Floor7 wudixin96 | Posted 2007-06-30 14:05 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
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? |
|
| Floor8 terse | Posted 2007-06-30 14:06 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
for /f "delims=" %i in ('dir download /b/s') do @echo %~nxi
|
|
| Floor9 wjh6088 | Posted 2007-06-30 14:09 |
| 初级用户 Posts 39 Credits 85 | |
|
对于 `for /f "tokens=1,2,3* delims=\" %i in ('dir download /b/s') do @echo %k`
|
|
| Floor10 blogsss | Posted 2007-06-30 14:23 |
| 初级用户 Posts 14 Credits 36 | |
Originally posted by wudixin96 at 2007-6-30 02:05 PM: 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 |
|
| Floor11 wudixin96 | Posted 2007-06-30 14:32 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
Is this so? |
|
| Floor12 wjh6088 | Posted 2007-06-30 14:33 |
| 初级用户 Posts 39 Credits 85 | |
|
for /f "tokens=1,2,* delims=\" %i in ('dir c:\download /a-d/b/s') do @echo %k
|
|
| Floor13 blogsss | Posted 2007-06-30 14:40 |
| 初级用户 Posts 14 Credits 36 | |
Originally posted by wudixin96 at 2007-6-30 02:32 PM: 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 ] |
|
| Floor14 qinbuer | Posted 2007-06-30 14:46 |
| 高级用户 Posts 228 Credits 512 | |
|
@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 ] |
|
| Floor15 wudixin96 | Posted 2007-06-30 14:54 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
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.
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |