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-02 20:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Help) About batch processing file search, thanks! View 1,734 Replies 13
Original Poster Posted 2006-12-21 16:16 ·  中国 广东 深圳 电信
初级用户
Credits 93
Posts 35
Joined 2006-12-20 10:43
19-year member
UID 74034
Gender Male
Status Offline
How to use batch processing to open the folder where the file is located after searching for the specified file.

........Enter the file name to search for:
.......Searching, please wait......
Open the folder where the file is located
Floor 2 Posted 2006-12-21 23:49 ·  中国 上海 静安区 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
Try this:
Note that if there are many files, it may make your machine work hard!!

for /r %%i in (*.bat) do start %cd:~0,2%%%~pi
Floor 3 Posted 2006-12-22 05:46 ·  中国 广东 深圳 电信
初级用户
Credits 93
Posts 35
Joined 2006-12-20 10:43
19-year member
UID 74034
Gender Male
Status Offline
Is there a better way!
Floor 4 Posted 2006-12-22 06:17 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
First, use tree to make a directory count for each partition and save it to a specified text, then search for files in the text.
Floor 5 Posted 2006-12-22 06:18 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
@echo off
set /p a=Please enter the file to search (including extension):
echo Searching, please wait.........
for %%i in (c d e f g h) do @(
for /f %%j in ('dir %%i:\%a% /s/a/b') do start %%~pj
)
Floor 6 Posted 2006-12-22 06:26 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Do you want to find the file everywhere or only in one place?

If it is unique, the following code should work (copied from lxmxn):

@echo off
set/p input=Please enter the file name to query
for %%i in (c d e f) do (
for /f "delims=" %%a in ('dir /s/b/a-d %%i:\%input% 2^>nul') do (
start %%~dpsa&&goto :eof
)
)
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 7 Posted 2006-12-22 06:50 ·  中国 广东 深圳 电信
初级用户
Credits 93
Posts 35
Joined 2006-12-20 10:43
19-year member
UID 74034
Gender Male
Status Offline
Thanks tianzizhi, there is another question. With your method, it cannot achieve full-disk search, only search the files in the drive where the bat is placed. It won't open the C:\Program Files folder, only the C drive.
Floor 8 Posted 2006-12-22 06:54 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
~~~>_<~~~
Try my......
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 9 Posted 2006-12-22 06:54 ·  中国 广东 深圳 电信
初级用户
Credits 93
Posts 35
Joined 2006-12-20 10:43
19-year member
UID 74034
Gender Male
Status Offline
The method of ccwan doesn't work either. If you don't believe it, put the BAT on the desktop and see if you can find the files on drive D!
Floor 10 Posted 2006-12-22 06:56 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
I've tried many times, it's okay!
What file are you looking for that can't be opened on d:?
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 11 Posted 2006-12-22 07:11 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
In fact, this batch processing can still be modified. For example, if you want to find 1.txt but there are 3 to 5 in the computer, then remove &&goto :eof in the code. There will be as many 1.txts as there are folders opened. If you don't mind being tedious. ^_^
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 12 Posted 2006-12-22 07:26 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
Modify the modification of ccwan to support file names with spaces.


@echo off
set/p input=Please enter the file name to query:
for %%i in (c d e f) do (
for /f "usebackq delims=" %%a in (`dir/s/b/a-d "%%i:\%input%" 2^>nul`) do (
start " " "%%~dpsa"
)
)

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 13 Posted 2006-12-22 08:38 ·  中国 广东 深圳 电信
初级用户
Credits 93
Posts 35
Joined 2006-12-20 10:43
19-year member
UID 74034
Gender Male
Status Offline
Thanks tao0610, this is what I need, and I've learned something again.
Floor 14 Posted 2006-12-22 09:00 ·  中国 甘肃 兰州 城关区 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Why is there no space after "start"?
Forum Jump: