|
smileseeker
中级用户
  
积分 316
发帖 83
注册 2005-3-1
状态 离线
|
『楼 主』:
我的findstr怎么了
使用 LLM 解释/回答一下
D:\scripts>for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
D:\scripts>echo 123 | findstr "123"
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
^CEnter your code:Enter your code:Enter your code:Enter your code:Enter your cod
e:Enter your code:Enter your code:Enter your code:^C^CEnter your code:Enter your
code:^C^CERROR!!!
D:\scripts>for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
D:\scripts>echo 123 | findstr "123"
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
^CEnter your code:Enter your code:Enter your code:Enter your code:Enter your cod
e:Enter your code:Enter your code:Enter your code:^C^CEnter your code:Enter your
code:^C^CERROR!!!
|
|
2006-9-27 01:18 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
你的代码有点问题,试试下面这个语句呢:
for /F %i in ('dir /ad /s /b') do (echo %~ni|findstr "123">nul && echo %~ni)
There is something wrong with your code. Try the following statement:
for /F %i in ('dir /ad /s /b') do (echo %~ni|findstr "123">nul && echo %~ni)
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 01:23 |
|
|
smileseeker
中级用户
  
积分 316
发帖 83
注册 2005-3-1
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
好像还是不行啊
D:\scripts>for /F %i in ('dir /ad /s /b') do (echo %~ni | findstr "123" && ec
ho %~ni )
D:\scripts>(echo 123 | findstr "123" && echo 123 )
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
It still doesn't seem to work.
D:\scripts>for /F %i in ('dir /ad /s /b') do (echo %~ni | findstr "123" && echo %~ni )
D:\scripts>(echo 123 | findstr "123" && echo 123 )
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
Enter your code:Enter your code:Enter your code:Enter your code:Enter your code:
|
|
2006-9-27 01:30 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
你干脆把下面的代码放到批处理来执行算了,在CMD窗口里很受干扰的。
@echo off
for /F %%i in ('dir /ad /s /b') do (echo %%~ni|findstr "123">nul && echo %%~ni)
pause
Why don't you just put the following code in a batch file to execute? It's quite distracting in the CMD window.
@echo off
for /F %%i in ('dir /ad /s /b') do (echo %%~ni|findstr "123">nul && echo %%~ni)
pause
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 02:01 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
你的bat名字是不是findstr.bat ?
Is your bat name findstr.bat?
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-9-27 02:11 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
LZ想要实现什么效果???不明白,是找123命名的文件夹吗?还是???
LZ wants to achieve what effect??? Don't understand, is it to find the folder named 123? Or something else???
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-9-27 02:34 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-9-27 08:12 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by smileseeker at 2006-9-27 01:18:
D:\scripts>for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
D:\scripts>echo 123 | findstr "123"
Enter your code:Enter your code:Enter your code:Enter yo ...
很明显你的代码是错误的. dir /ad /s /b是查找文件夹, 而%~ni为扩展到文件名. 哪里来的文件名吗? 根本就只有路径.
代码修改为:
@echo off
for /F "tokens=*" %%i in ('dir /a-d /s /b *.*') do (
echo %%~ni | findstr "123" && echo 找到匹配文件
)
pause
请保存为批处运行.
Originally posted by smileseeker at 2006-9-27 01:18:
D:\scripts>for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
D:\scripts>echo 123 | findstr "123"
Enter your code:Enter your code:Enter your code:Enter yo ...
It is obvious that your code is wrong. dir /ad /s /b is to find folders, and %~ni is expanded to the file name. Where is the file name? There is only the path at all.
Modify the code to:
@echo off
for /F "tokens=*" %%i in ('dir /a-d /s /b *.*') do (
echo %%~ni | findstr "123" && echo Found matching file
)
pause
Please save it as a batch file to run.
|
|
2006-9-27 09:25 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:25:
很明显你的代码是错误的. dir /ad /s /b是查找文件夹, 而%~ni为扩展到文件名. 哪里来的文件名吗? 根本就只有路径.
代码修改为:
@echo off
for /F "t ...
本来windows就认不出什么是文件什么是路径的,问个问题,有个文件夹a.txt ,你说它是文件夹还是文件???更何况是机器,它怎么认的出
Originally posted by pengfei at 2006-9-27 09:25:
Obviously your code is wrong. dir /ad /s /b is to find folders, and %~ni is to expand to the file name. Where is the file name? There is only the path at all.
Modify the code as:
@echo off
for /F "t ... Originally, Windows can't distinguish what is a file and what is a path. Let's ask a question: there is a folder a.txt, do you say it is a folder or a file??? Moreover, how can a machine recognize it
|
|
2006-9-27 09:28 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
刚才测试了一下我的电脑没有出现错误提示.
我是认为%%~ni为扩展到文件名! 如果为路径扩展会出现错误.
Last edited by pengfei on 2006-9-27 at 09:40 ]
I just tested my computer just now and there were no error messages.
I think that %%~ni is expanded to the file name! If it is expanded to a path, an error will occur.
Last edited by pengfei on 2006-9-27 at 09:40 ]
|
|
2006-9-27 09:32 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:32:
刚才测试了一下我的电脑没有出现错误提示.
我是认为%%~ni为扩展到文件名! 如果为路径扩展会出现错误.
Last edited by pengfei on 2006-9-27 at 09:40 ]
cd c:\
md test
cd test
md 123
md 123456
for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
你执行这个看看,看看会不会出错
Originally posted by pengfei at 2006-9-27 09:32:
Just tested my computer and there were no error messages.
I think %%~ni expands to the file name! If it's a path expansion, an error will occur.
Last edited by pengfei on 2006-9-27 at 09:40 ]
cd c:\
md test
cd test
md 123
md 123456
for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
Please execute this and see if there will be an error
|
|
2006-9-27 09:42 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-9-27 09:28:
本来windows就认不出什么是文件什么是路径的,问个问题,有个文件夹a.txt ,你说它是文件夹还是文件???更何况是机器,它怎么认的出
此言差矣。CMD下的 dir 是可以区分出某个file到底是文件夹还是文件的,要不然,dir命令还要 /ad 和 /a-d 这两个参数干什么呢?如果按照你的理解,它们岂不成了摆设了吗?你建立一个a.txt的文件夹,分别用 dir /ad 和 dir /a-d 来试试,看dir是不是能正确区分出来。
只是在for语句的扩展中,%~xi 简单地认为最后一个以点号结束的字符串是后缀名,从而造成把文件夹a.txt的后缀名误认为是.txt的情况。如果据此就认为windows不能正确区分文件和路径的话,那就大错特错了。不过这也证明了for语句的扩展是有bug的,使用的时候千万要小心。
Originally posted by he200377 at 2006-9-27 09:28:
Windows originally can't distinguish what is a file and what is a path. Let's ask a question: there is a folder named a.txt, do you say it is a folder or a file??? Moreover, how can a machine recognize it
That's not right. The dir command under CMD can distinguish whether a certain file is a folder or a file. Otherwise, why are there the two parameters /ad and /a-d for the dir command? According to your understanding, wouldn't they be useless? Create a folder named a.txt, and try using dir /ad and dir /a-d respectively to see if dir can distinguish them correctly.
Just in the extension of the for statement, %~xi simply thinks that the last string ending with a dot is the suffix, thus causing the situation of mistakenly thinking that the suffix of the folder a.txt is .txt. If you think that Windows can't distinguish files and paths correctly based on this, that's completely wrong. But this also proves that there is a bug in the extension of the for statement, and you must be careful when using it.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 09:44 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
是的, 看来是我错了. 没有经过测试, 只是理论推断.
Yes, it seems I was wrong. It was just theoretical inference without testing.
|
|
2006-9-27 09:44 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
分别用 dir /ad 和 dir /a-d 来试试
一言指明哈~原来 dir 可以排除目录的,搞的上次为了这个排除目录而想方法,这次回去再 *.exe /? 看看
Try using dir /ad and dir /a-d respectively. A word to clarify~ It turns out that dir can exclude directories. I was trying to figure out a way to exclude directories last time. This time, I'll go back and check *.exe /?
|
|
2006-9-27 09:52 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-9-27 09:42:
cd c:\
md test
cd test
md 123
md 123456
for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
你执行这个看看,看看会不会出错
从这段代码来看,你是在CMD窗口下执行的。从你的整体意思来看,你是想先转到 C 盘根目录下之后再创建文件夹,但是你最开始的那一句就没写对,因为它并不能跳转到 C 盘根目录下,请想想这是为什么;并且,你最后的for语句不完整,所以就算你前面的代码都写对了,执行到这里的时候也会发生错误的。
以上代码我是在批处理中把 %i 替换成 %%i 来执行的,所以导致以上言论出了错,在此更正,并对导致别人的误解表示歉意。
Last edited by namejm on 2006-9-27 at 10:16 ]
Originally posted by he200377 at 2006-9-27 09:42:
cd c:\
md test
cd test
md 123
md 123456
for /F %i in ('dir /ad /s /b') do echo %~ni | findstr "123"
Please execute this and see if it will go wrong
From this code, you are executing in the CMD window. Judging from your overall meaning, you want to first go to the root directory of drive C and then create folders, but the first sentence you wrote is not correct because it cannot jump to the root directory of drive C. Think about why; and your final for statement is incomplete, so even if your previous code is all correct, an error will occur when executing here.
The above code I executed in a batch file by replacing %i with %%i, so the above remarks were wrong. I correct it here and apologize for causing misunderstandings to others.
Last edited by namejm on 2006-9-27 at 10:16 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 09:53 |
|