We all need sometimes to find a certain file on a local disk drive. It is not hard to implement search by name with the help of batch files. But what to do if you need to search for a file on all the drives available on a computer? The example script below shows how to perform it.
@echo off
setlocal
for %%i 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 (
for /f "tokens=*" %%a in ('dir /b /s /a-d %%i:\FileName.ext 2^>nul') do (
set "foundFile=%%a" & goto found
))
echo File not found
goto :EOF
:found
echo File found - %foundFile%
As far as you can see, we simply look through all letters for logical drives and then search for the needful file on the each drive separately.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment