Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search MS-DOS批处理:目录中的非递归文件搜索_Search_Batch File - Fatal编程技术网

Search MS-DOS批处理:目录中的非递归文件搜索

Search MS-DOS批处理:目录中的非递归文件搜索,search,batch-file,Search,Batch File,我的目标是在C:\drive中的任何目录中搜索名为“setup95.exe”的文件,而不是这些目录的目录。如果文件存在,则需要将路径写入名为%getpath%的变量 我最初只是想简单地使用dir,但它没有达到我的期望。我需要在C:\中找到任何目录并搜索它。作为一个例子,假设我在C:\中有一个名为\uu_neverhood的文件夹。在该文件夹中,有一个名为setup95.exe的文件。程序不知道它是哪个文件夹。它只知道它在C:\中,所以它需要搜索C:\中的每个目录以查找setup95.exe 更新

我的目标是在C:\drive中的任何目录中搜索名为“setup95.exe”的文件,而不是这些目录的目录。如果文件存在,则需要将路径写入名为
%getpath%
的变量

我最初只是想简单地使用
dir
,但它没有达到我的期望。我需要在C:\中找到任何目录并搜索它。作为一个例子,假设我在C:\中有一个名为
\uu_neverhood
的文件夹。在该文件夹中,有一个名为
setup95.exe
的文件。程序不知道它是哪个文件夹。它只知道它在C:\中,所以它需要搜索C:\中的每个目录以查找
setup95.exe

更新:新代码。它找到了文件,但对磁盘驱动器没有好处。下面是代码的摘录:

@ECHO OFF
SETLOCAL 
SET "traversity=C:\Program Files (x86)\"
if not exist "C:\Program Files (x86)" SET "traversity=C:\Program Files\"

SET intricacy=%traversity%The Neverhood Restoration Project
SET obscurity=%traversity%DreamWorks Interactive
SET psychedelia=%obscurity%\Neverhood
SET abstraction=WAVistaWin7.exe

:removenrp
if exist "%traversity%The Neverhood Restoration Project Julia\unins000.exe" ( 
    "%traversity%The Neverhood Restoration Project Julia\unins000.exe"
)

:delreg
if %PROCESSOR_ARCHITECTURE%==x86 ( 
    reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DreamWorks Interactive" /f
) else ( 
    if %PROCESSOR_ARCHITECTURE%==AMD64 ( 
        reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DreamWorks Interactive" /f
    ) else (
        reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\DreamWorks Interactive" /f
)) 

if exist "%obscurity%" echo y | rmdir /S /Q "%obscurity%"


mkdir "%obscurity%"
mkdir "%psychedelia%"
copy /Y "%~dp0%abstraction%" "%psychedelia%"
for /d %%a in (c:\*) do for /f "delims=" %%i in ('dir /b /a-d "%%~a\setup95.exe" 2^>nul') do set "getpath=%%~a"
if defined getpath (echo path is %getpath%) else rem ok 

if exist "%getpath%setup95.exe" (
    echo MSGBOX "Pyroneous did not distribute the Neverhood illicitly to you. Remember that the only legal way to run the Neverhood is to buy it. We will still permit you to install the Neverhood, but we are not responsible for your actions. You can read our full purposes at theneverhood.sourceforge.net. Thanks!" > %temp%\TEMPmessage.vbs
    call %temp%\TEMPmessage.vbs
    del %temp%\TEMPmessage.vbs /f /q
    reg import "%~dp0neverhood.reg"
    START "%getpath%setup95.exe"
) else (
    for %%D in (a b 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 vol %%D: >output 2>output && if exist %%D:\setup95.exe set DRIVE=%%D
    if not defined DRIVE echo It appears you don't have the Neverhood on your computer. Please check http://theneverhood.sourceforge.net/setup/ for more information. && pause
    if exist "%DRIVE%:\setup95.exe" (
        echo MSGBOX "Hey. Thank you for purchasing the Neverhood. That is, if you're not using an burned ISO/exploitation." > %temp%\TEMPmessage.vbs
        call %temp%\TEMPmessage.vbs
        del %temp%\TEMPmessage.vbs /f /q
        reg import "%~dp0neverhood.reg"
        START D:\setup95.exe
) )

输出返回以下内容:

C:\Users\b\Desktop\somnacea\files\thankyousanta\necessity>install.bat
ERROR: The system was unable to find the specified registry key or value.
The process tried to write to a nonexistent pipe.
        1 file(s) copied.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
It appears you don't have the Neverhood on your computer. Please check http://th
eneverhood.sourceforge.net/setup/ for more information.
Press any key to continue . . .

可悲的是,你的问题很清楚。举个例子就好了

您是否询问如何检测所述文件是否存在于您指定的目录中,或者是否存在任何特定文件

@ECHO OFF
SETLOCAL
:: version 1 - if you want to specify the drive and path and file
FOR /f %%i IN ("%~1") DO IF EXIST "%%i" (SET getpath=%%~pi) ELSE (SET getpath=)
ECHO (1) getpath=%getpath%

:: version 2 - if you want to specify path and assume drive and file
FOR /f %%i IN ("c:\%~1\setup95.exe") DO IF EXIST "%%i" (SET getpath=%%~pi) ELSE (SET getpath=)
ECHO (2) getpath=%getpath%
使用参数
“c:\directory I\want\find\setup95.exe”
运行此命令时,应使用第一个版本(
getpath
如果文件存在,则设置为路径,否则为空)

使用参数
“\directory I\want\find”
运行此命令应适用于第二个版本(
getpath
如果文件存在,则设置为路径,否则为空)

但是-如果您已经知道您的路径是什么,为什么不直接使用
if exist“c:\path I want\to known\about\setup95.exe”

如果您不知道,您所说的“C:\drive中的任何目录——但不是这些目录的目录”是什么意思


如果有更多数据:

@ECHO OFF
SETLOCAL
SET "getpath="
FOR /f "delims=" %%i IN ('dir /s /b /a-d c:\setup95.exe'
  ) DO IF DEFINED getpath (ECHO also found IN %%~pi) ELSE (SET getpath=%%~pi)
IF DEFINED getpath (ECHO first found AT %getpath%) ELSE (ECHO NOT found)
应该显示找到的第一个位置,无论是在更多的地方找到的还是在所有的地方找到的