Checking via WMIC to see if home folder (h:) exists

July 2, 2019 at 12:33:41
Specs: Windows 10
Afternoon I am attempting to create a robocopy backup script but I would like to check before the script processes to see if the home folder (H:) exists so I have something like this

for /F “tokens=2,3,4 ” %%i in (`wmic path Win32_LogicalDisk Where DriveType="4" get DeviceID, drivetype`) do (
if %%l equ H: (
echo %%i is home folder %%l.
set backuphome=%%i
But I am new to using for token commands

Any suggestions

See More: Checking via WMIC to see if home folder (h:) exists

Reply ↓  Report •

July 2, 2019 at 13:27:58
Sounds overcomplicated.
dir h: >NUL 2>NUL && set "hExists=Y" || set "hExists=N"

How To Ask Questions The Smart Way

Reply ↓  Report •

July 2, 2019 at 20:54:52
this also seemed to work on my end:
if exist h: echo h: ok

::as for further testing, this worked:
wmic path Win32_LogicalDisk Where DriveType="3" get DeviceID, drivetype
rem this did NOT: "invalid GET expression" or "invalid verb":
for /F "tokens=*" %%i in ('wmic path Win32_LogicalDisk get DeviceID, drivetype') do echo %%i
I tried your script (after making some syntax corrections), and still could not get wmic to operate inside a for loop: "invalid verb" (meaning "get", I guess.). outside a loop it shows output. Note that output from wmic is in Unicode, and batch (at least at my primitive level - win-7) does not handle Unicode. Unicode files can be "typed" to convert to ascii, which batch can handle.
I think razor has it covered, unless the drivetype is critical. another option is fsutil:
fsutil fsinfo drivetype h:

then parse the results.

message edited by nbrane

Reply ↓  Report •

July 2, 2019 at 23:17:29
Your idea is better. I like IF EXIST more.

EDIT: Drive type 4 is network drive, so if it being a network drive is important, NET USE H: could also be used.

How To Ask Questions The Smart Way

message edited by Razor2.3

Reply ↓  Report •
Related Solutions

Ask Question