我的目標是在C:\驅動器的ANY目錄中搜索名爲「setup95.exe」的文件,但不搜索這些目錄的目錄 - 。如果文件存在,那麼我需要將路徑寫入名爲%getpath%
的變量。MS-DOS批處理:在目錄中搜索非遞歸文件
我最初試圖簡單地使用dir
,但它不符合我的期望。我需要獲取C:\中的任意目錄並搜索它。作爲一個示例,假設我在C:\中有一個文件夾,名爲__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 . . .