VBS로 파일 찾기 및 위치 폴더 열기

VBS로 파일 찾기 및 위치 폴더 열기

각 하드 드라이브 파티션에서 파일을 검색한 다음 파일이 발견되면 파일의 위치 폴더를 여는 스크립트를 vbs(또는 기타)에서 만드는 방법이 있습니까? 따라서 H:\stuff\texts\의 H: 드라이브에 있는 "rand.txt" 파일을 찾으려면 코드는 C:,D:,E:,F:에서 찾습니다. H에 있는 경우: "texts" 폴더를 엽니다. cmd로 해봤는데 실제로는 안되네요...

답변1

다음은 Windows 배치 솔루션입니다(시간이 많이 걸릴 수 있음).

@ECHO OFF >NUL
@SETLOCAL enableextensions disabledelayedexpansion
for %%G 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 (
   if exist %%G:\NUL (
       echo %%G: drive
       for /F "tokens=*" %%H in ('where /r %%G:\ rand.txt 2>NUL') do (

         echo %%H
         explorer.exe /e,/select,"%%~fH"

       )
     )
   )
@ENDLOCAL
@GOTO :eof

대신 echo %%H파일 이름에 대한 전체 경로가 있습니다...

편집하다: where /r %%G:\ rand.txt 2>NUL(중요: ) 시작 디렉터리가 존재하지 않는 경우 다음 예와 같이 2>NUL오류 메시지를 제거합니다 (단편 열거).ERROR: The system cannot find the file specifiedINFO: Could not find files for the given pattern(s)

d:\xxx>where /r C:\bat\ randx.txt
ERROR: The system cannot find the file specified.

d:\xxx>echo %errorlevel%
2

d:\xxx>where /r d:\bat\ randx.txt
INFO: Could not find files for the given pattern(s).

d:\xxx>echo %errorlevel%
1

d:\xxx>where /r d:\bat\ rand.txt
d:\bat\files\rand.txt

d:\xxx>echo %errorlevel%
0

d:\xxx>

답변2

Powershell에서 이 작업을 수행해야 합니다.

gwmi Win32_LogicalDisk | Select-Object -expand DeviceID | %{$drive = $_; $drive; ls "$drive\rand.txt" -recurse | %{ii (Split-Path $_)}}

관련 정보