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-06-21 04:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Solved) How to hide the results displayed during the for search file process View 2,034 Replies 23
Floor 16 Posted 2007-10-10 21:23 ·  中国 江苏 常州 武进区 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
@echo off
setlocal enabledelayedexpansion
set "aa_dir="
for %%a in (F E D C) do (
for /f "delims=" %%i in ('dir /a /b /s "%%a:\avp.exe" 2^>nul') do if not defined aa_dir set aa_dir=%%~dpi
)
start "" %aa_dir%

pause

The meaning is: First, turn off the echo of commands. Then enable delayed variable expansion. Initialize the variable aa_dir to an empty string. Then loop through drives F, E, D, C. For each drive, use the dir command to search for avp.exe in all directories and subdirectories. If aa_dir is not defined, set aa_dir to the drive and directory path where avp.exe is found. Then start the program located in aa_dir. Finally, pause to keep the window open.
Floor 17 Posted 2007-10-10 23:13 ·  中国 河北 保定 联通
初级用户
Credits 114
Posts 49
Joined 2006-10-08 06:47
19-year member
UID 64907
Status Offline
Originally posted by terse at 2007-10-10 21:23:
@echo off
setlocal enabledelayedexpansion
set "aa_dir="
for %%a in (F E D C) do (
for /f "delims=" %%i in ('dir /a /b /s "%%a:\avp.exe"2^>nul') do if not define ...

Thanks. But it still doesn't work. It prompts "The system cannot find the file C:\Documents."
Floor 18 Posted 2007-10-10 23:16 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
start "" "%aa_dir%"

The start didn't have quotes added.
Floor 19 Posted 2007-10-10 23:42 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
@echo off
for %%i in (F E D C) do (
dir /a /b /s %%i:\avp.exe|find /i "avp.exe">temp.txt
if not errorlevel 1 goto end
)
echo Not found avp.exe
pause
:end
cls
set /p Program=<temp.txt
echo start "%Program%"
pause
第一高手 第二高手

Floor 20 Posted 2007-10-11 00:16 ·  中国 河北 保定 联通
初级用户
Credits 114
Posts 49
Joined 2006-10-08 06:47
19-year member
UID 64907
Status Offline
Originally posted by fastslz at 2007-10-10 23:42:
@echo off
for %%i in (F E D C) do (
dir /a /b /s %%i:\avp.exe|find /i "avp.exe">temp.txt
if not errorlevel 1 goto end
)
echo No avp.exe found
pause
:end
cls
set /p ...

This works, but it cannot solve the problem of spaces in path names.
Floor 21 Posted 2007-10-11 00:34 ·  中国 湖北 武汉 中国科学院武汉分院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Originally posted by bd540 at 2007-10-10 13:17:
When this code runs, it displays messages like "Device not ready" and "File not found". How to hide these messages? I added >NUL in several places and got errors.
for %%a in (Z Y X W ...



This question has been asked before.
I gave a solution at that time

Actually, it's in this format:----It can handle file names and paths with spaces

for "delims=" %%a in (xx) do ( ...... ) >nul 2>nul

...... represents all the operations you want to do, no matter how many lines or commands;

That ">nul 2>nul" must be added right after the last parenthesis ")" of for...do (...).
This can suppress any messages!

Here's an example:


@echo off

for /f "delims=" %%i in ("%cd%") do (
echo %%i
dir c:\
dir x:\

) >nul 2>nul




[ Last edited by scriptor on 2007-10-11 at 12:36 AM ]
Floor 22 Posted 2007-10-11 00:37 ·  中国 湖北 武汉 中国科学院武汉分院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Originally posted by bd540 at 2007-10-11 00:16:

This is okay, but the problem of pathname spaces cannot be solved.



You put all the displayed information into a temporary file
Hehe....

There will still be in the file!!
Floor 23 Posted 2007-10-11 02:27 ·  中国 河北 保定 联通
初级用户
Credits 114
Posts 49
Joined 2006-10-08 06:47
19-year member
UID 64907
Status Offline
Solved:
1. Hide the prompt: The ">nul 2>nul" must be attached right after the last parenthesis ")" of for...do (...).
2. Space issue: According to fastslz's code, after adding the replacement character code, solve it by removing *.exe and then adding "".

Thanks to the numerous friends who replied to this post!!!
Floor 24 Posted 2007-10-13 15:18 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by bd540 at 2007-10-10 23:13:

Thanks. But it still doesn't work, prompting "The system cannot find the file C:\Documents."


Finally, I forgot to add a "".

@echo off
setlocal enabledelayedexpansion
set "aa_dir="
for %%a in (F E D C) do (
for /f "delims=" %%i in ('dir /a /b /s "%%a:\avp.exe" 2^>nul') do if not defined aa_dir set aa_dir=%%~dpi
)
start "" "%aa_dir%"

It passed the test here
Forum Jump: