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-06 02:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » What's wrong with my findstr View 2,973 Replies 22
Floor 16 Posted 2006-09-27 09:55 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
What exactly is the problem with the building's error? I saw that kind of error before.
Floor 17 Posted 2006-09-27 09:57 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by namejm at 2006-9-27 09:53:


  From this code, it seems you are executing in the CMD window. Judging from your overall meaning, you want to first switch to the root directory of drive C and then create a folder, but the first sentence you started with didn't have...

Why do I get no errors when I execute it??? Confused
Floor 18 Posted 2006-09-27 09:59 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
In fact, there are still bugs when the for is extended to file names:

In the for statement, when executing dir /ad or dir /a-d and using %%~ni to extend to the file name, the FOR statement processing mechanism may be to remove the "." after the last path "\" symbol and the following suffix, and only display the file name;

And if /ad only searches for folders, and there is no "." after the last path "/", it will display the entire last directory name.

[ Last edited by pengfei on 2006-9-27 at 12:10 ]
Floor 19 Posted 2006-09-27 10:04 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by he200377 at 2006-9-27 09:57:

Why is there no error when I execute it??? puzzled


There is a flaw in the first command of your code. Suppose you run it on drive D...

But the expansion of %%~ni in the for statement does have a bug. I didn't test it at that time. Later I found that there was a problem with its expansion mechanism.

[ Last edited by pengfei on 2006-9-27 at 10:24 ]
Floor 20 Posted 2006-09-28 04:06 ·  中国 福建 三明 电信
中级用户
★★
Credits 316
Posts 83
Joined 2005-03-01 00:00
21-year member
UID 36626
Gender Male
Status Offline
Thanks to the enthusiastic help of all friends

The purpose of the younger brother is like this. Through the following code

echo.>temp.txt
for /f %%i in ('dir /ad /s /b') do (echo %%~ni|findstr "^*$" && echo %%i >>temp.txt)
for /f %%i in (temp.txt) do del /q %%i\*.*

Solve http://www.cn-dos.net/forum/viewthread.php?tid=23404&fpage=1

But it is stuck on findstr
Floor 21 Posted 2006-09-28 04:14 ·  中国 福建 三明 电信
中级用户
★★
Credits 316
Posts 83
Joined 2005-03-01 00:00
21-year member
UID 36626
Gender Male
Status Offline
Originally posted by namejm at 2006-9-27 09:44 AM:


This statement is incorrect. The 'dir' command under CMD can distinguish whether a file is a folder or a file. Otherwise, why are there the two parameters /ad and /a-d for the 'dir' command? If according to your understanding...



Agreed

D:\scripts>for /f %i in ("\123.456") do echo %~ni

D:\scripts>echo 123
123
Floor 22 Posted 2006-09-28 04:24 ·  中国 福建 三明 电信
中级用户
★★
Credits 316
Posts 83
Joined 2005-03-01 00:00
21-year member
UID 36626
Gender Male
Status Offline
This is a batch script I found on the forum before

set /p aa=Enter your code:
echo %aa% | findstr "^[a-z][A-Z]*$"||echo ERROR!!!
pause

I remember it seemed to be executable at that time. Now it's actually such an execution result

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

D:\scripts>set /p aa=Enter your code:
Enter your code:
D:\scripts>echo dfg | findstr "^[a-z][A-Z]*$" || echo ERROR!!!

Speechless
Floor 23 Posted 2007-10-11 21:25 ·  中国 浙江 温州 电信
初级用户
★★
Credits 158
Posts 89
Joined 2007-04-25 08:06
19-year member
UID 86402
Gender Male
Status Offline
Forum Jump: