Board logo

标题: [已解决]全盘查找文件,然后... [打印本页]

作者: tireless     时间: 2008-9-20 16:59    标题: [已解决]全盘查找文件,然后...
预期效果:
请输入要查找的文件名:wo.exe 1 c:\WINDOWS\wo.exe 2 d:\commandline tools\wo.exe (”逼“一声) 查询结束 请选择...或按回车键退出. . .
• 每条结果前按顺序加上数字。 • 输入数字,回车,则执行命令。直接回车就退出。 执行的命令是:例如输入 1,回车,则执行 explorer /select,c:\WINDOWS\wo.exe [ Last edited by tireless on 2008-9-20 at 12:05 AM ]

作者: slore     时间: 2008-9-20 17:19
貌似for套dir就能实现。。。

作者: moniuming     时间: 2008-9-20 17:26
试试这个:
@echo off
setlocal enabledelayedexpansion
set /p str=请输入要查找的文件名:
set "drv=c d e f g h i j k l m n"
for %%a in (%drv%) do (
   if exist %%a: (
      for /f "delims=" %%b in ('dir /s/b/a-d "%%a:\%str%" 2^>nul') do (
         set /a "n+=1"
         set "_!n!=%%b"
         echo !n!   %%b
      )
   )
)
echo 
echo 查询结束...
:here
set "var="
set /p var=请选择:
if not defined var exit
start "" "!_%var%!"
goto :here

作者: HAT     时间: 2008-9-20 17:28
@echo off
set /p file=请输入要查找的文件名:
if "%file%" equ "" (
  goto :eof
) else if "%file%" equ "1" (
  start explorer /select,c:\WINDOWS\wo.exe
  goto :eof
)
>"a.txt" type nul
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if exist %%a: (
    for /r %%a: %%h in (%file%) do ( 
      >>"a.txt" echo %%h
    )
  )
)
findstr /n .* "a.txt"
echo 

作者: HAT     时间: 2008-9-20 17:39
@echo off
set /p file=请输入要查找的文件名:
if "%file%" equ "" (
  goto :eof
) else if "%file%" equ "1" (
  start explorer /select,c:\WINDOWS\wo.exe
  goto :eof
)
>"a.txt" type nul
for %%a in ("%file%") do (
  set name=%%~na
  set ext=%%~xa
)
set ext=%ext:~1%
for /f "skip=1 delims=" %%a in ('wmic datafile where "filename='%name%' and Extension='%ext%'" get name /value') do (
  >>"a.txt" echo %%a
)
findstr /n .* "a.txt"
echo 
echo 查询结束
echo.
echo 请选择...或按回车键退出. . .
pause>

作者: tireless     时间: 2008-9-20 17:47
额。不好意思,那个执行的命令是 explorer /select,所选数字的结果 例如有这些结果: 1 c:\1.txt 2 d:\1.txt 3 e:\1.txt 选择 1 回车后,则执行 explorer /select,c:\1.txt 选择 2 的话,则执行 explorer /select,d:\1.txt 选择 3 的话,则执行 explorer /select,e:\1.txt

作者: moniuming     时间: 2008-9-20 19:12
explorer还有个/select参数?

作者: HAT     时间: 2008-9-20 19:18    标题: Re 7楼
yes
  在Windows中,相信大家对“Explorer.exe”并不陌生!通常情况下,在“开始→运行”中输 入“Explorer.exe”命令就能以“资源管理器”方式打开“我的文档”。其实,Explorer.exe还有很多鲜为人知的参数。   命令格式   Explorer [/n][/e][[,/root],[path]][[,/select],[path filename]]   参数说明   /n表示以“我的电脑”方式打开一个新的窗口,通常打开的是Windows安装分区的根目录。   /e表示以“资源管理器”方式打开一个新的窗口,通常打开的也是Windows安装分区的根目录。   /root,[path]表示打开指定的文件夹,/root表示只显示指定文件夹下面的文件(夹),不显示其它磁盘分区和文件夹;[path]表示指定的路径。   如果不加/root参数,而只用[path]参数,则可以显示其它磁盘分区和文件夹中的内容。另外,[path]还可以指定网络共享文件夹。   /select,[path filename]表示打开指定的文件夹并且选中指定的文件,[path filename]表示指定的路径和文件名。   如果不加/select参数,则系统会用相应的关联程序打开该文件。如果[path filename]不跟文件名就会打开该文件夹的上级目录并选中该文件夹。

作者: moniuming     时间: 2008-9-20 19:44    标题: 六楼
@echo off
setlocal enabledelayedexpansion
set /p str=请输入要查找的文件名:
echo.
set "drv=c d e f g h i j k l m n"
for %%a in (%drv%) do (
   if exist %%a: (
      for /f "delims=" %%b in ('dir /s/b/a-d "%%a:\%str%" 2^>nul') do (
         set /a "n+=1"
         set "_!n!=%%b"
         echo !n!   %%b
      )
   )
)
echo 
echo 查询结束...
:here
set "var="
set /p var=请选择...或回车退出...:
if not defined var exit
explorer /select,"!_%var%!"
goto :here
太感谢楼主和HAT了,要不还真不知道explorer还有参数,谢谢两位!!!

作者: tireless     时间: 2008-9-20 19:44    标题: re 8楼
格式写得不准确
Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>] /n Opens a new single-pane window for the default selection. This is usually the root of the drive Windows is installed on. If the window is already open, a duplicate opens. /e Opens Windows Explorer in its default view. /root,<object> Opens a window view of the specified object. /select,<object> Opens a window view with the specified folder, file or application selected. Examples: Example 1: Explorer /select,C:\TestDir\TestApp.exe Opens a window view with TestApp selected. Example 2: Explorer /e,/root,C:\TestDir\TestApp.exe This opens Explorer with C: expanded and TestApp selected. Example 3: Explorer /root,\\TestSvr\TestShare Opens a window view of the specified share. Example 4: Explorer /root,\\TestSvr\TestShare,select,TestApp.exe Opens a window view of the specified share with TestApp selected.