Condition:
I have 3 different folders. Folder1
, Folder2
and Folder 3
.
They are placed within an unknown USB drive.
Also the path is random.
Sometimes it's:
G:\Hello\Folder1
G:\Hello\Folder2
G:\hello\Folder3
and sometimes it's:
k:\Man\Google\Hey\Folder1
k:\Man\Google\Hey\Folder2
k:\Man\Google\Hey\Folder3
Means they are exist in random driver letters and also want to find with any random subfolder.
I used:
@echo off
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:\HOPE\EXTRA\Folder1 (
goto true
)
)
Here I don't want use (C D E F G H I J K L M N O P Q R S T U V W X Y Z)
because cmd
shows an error when driver letter is found but voume not mounted.
So I used following script
@echo off
CLS&ECHO.&ECHO Vol Access Type
echo.
SET "DVF="
FOR /F "tokens=1,*" %%A IN ('wmic logicaldisk get caption^, description ^| FIND ":"') DO (
VOL %%A >nul 2>&1 && (
CALL SET "DVF=%%DVF%% %%A"& ECHO %%A ^| ON. %%B) || (
ECHO %%A ^| OFF. %%B
)
)
ECHO.
ECHO.
ECHO Available Volumes: %DVF%
echo.
echo.
TIMEOUT /T 5
I want to find Folder1
, Folder2
and folder 3
from available volumes, but here output of %DVF%
is C: D: K: G:
So I want to search each available volumes to find those 3 folders are available in 1 volume and then set
that drive = %foldervol%
, or something, for next code or goto next
So can anyone help me using same script I mentioned here?
I want to find all three folders from unknown available volumes then echo folders found at volumename and goto next?
Questions should be limited to one problem only and the following should address that which is considered your primary issue, i.e. to output your USB drive letters. It will not search for, or locate your directories, as that is a completely different problem for which you've provided no code or other indication of a self attempt.
@Echo Off
SetLocal EnableExtensions
For /F Tokens^=2^ Delims^=^" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe
DiskDrive Where "InterfaceType='USB'" Assoc:List
/AssocClass:Win32_DiskDriveToDiskPartition 2^>NUL ^|
%SystemRoot%\System32\find.exe "__R"') Do For /F Tokens^=4^ Delims^=^" %%H In (
'%SystemRoot%\System32\wbem\WMIC.exe Path Win32_LogicalDiskToPartition
2^>NUL ^| %SystemRoot%\System32\find.exe "%%G"') Do Echo %%H
%SystemRoot%\System32\timeout.exe /T 5 /NoBreak 1>NUL
You would obviously replace Echo %%H
on line 9
with your 'folder' search code, using %%H\
as the root directory for each returned USB drive.