![]() |
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-11-11 08:42 |
47,815 topics / 349,930 posts / today 0 new / 48,291 members |
| DOS批处理 & 脚本技术(批处理室) » (Solved) How to hide the results displayed during the for search file process |
| Printable Version 2,759 / 23 |
| Floor16 terse | Posted 2007-10-10 21:23 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
@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. |
|
| Floor17 bd540 | Posted 2007-10-10 23:13 |
| 初级用户 Posts 49 Credits 114 | |
Originally posted by terse at 2007-10-10 21:23: Thanks. But it still doesn't work. It prompts "The system cannot find the file C:\Documents." |
|
| Floor18 wudixin96 | Posted 2007-10-10 23:16 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
start "" "%aa_dir%"
The start didn't have quotes added. |
|
| Floor19 fastslz | Posted 2007-10-10 23:42 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
@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 |
|
| Floor20 bd540 | Posted 2007-10-11 00:16 |
| 初级用户 Posts 49 Credits 114 | |
Originally posted by fastslz at 2007-10-10 23:42: This works, but it cannot solve the problem of spaces in path names. |
|
| Floor21 scriptor | Posted 2007-10-11 00:34 |
| 银牌会员 Posts 555 Credits 1,187 | |
Originally posted by bd540 at 2007-10-10 13:17: 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: [ Last edited by scriptor on 2007-10-11 at 12:36 AM ] |
|
| Floor22 scriptor | Posted 2007-10-11 00:37 |
| 银牌会员 Posts 555 Credits 1,187 | |
Originally posted by bd540 at 2007-10-11 00:16: You put all the displayed information into a temporary file Hehe.... There will still be in the file!! |
|
| Floor23 bd540 | Posted 2007-10-11 02:27 |
| 初级用户 Posts 49 Credits 114 | |
|
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!!! |
|
| Floor24 terse | Posted 2007-10-13 15:18 |
| 银牌会员 Posts 946 Credits 2,404 | |
Originally posted by bd540 at 2007-10-10 23:13: 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 |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |