Reputation: 75
I am trying to write a Windows batch script that is run locally on a number of Windows 10 client PCs on system startup. The script needs to select a specific drive dependent on the label (PHILLIPS) and then copy some files to it. I tried looping through all possible drive letters C,D,E, etc and compare the volume name with the string "PHILLIPS", but it doesnt work for some reason. I also tried different functions like :GetLabel for getting the Name of a volume.
Here is my attempt:
@echo off & setlocal enableextensions
for %d 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 (
set target_=%d:
::
call :vol %target_% label_
if /i "%label_%" == "%PHILIPS%" (
echo %%d%
xcopy \\SATVIE017\Softlib\philips\dpm8000-dpm8200-dpm8500_fwf_2.02.dpm target_\
endlocal & goto :EOF
)
)
It's my first time writing a batch script, so i dont know exactely what to look for solving this problem. Any advice would be very much welcomed as i dont want to to manually deploy the files on 100+ clients.
Upvotes: 1
Views: 721
Reputation: 38579
…and a similar idea using MountVol
:
@Echo Off
Set "_target="
For /F "Delims=\ " %%A In ('"MountVol|Find ":\""'
) Do Vol %%A 2>Nul|Find /I "PHILIPS" && (Set "_target=%%A\" & GoTo Done)
If Not Defined _target Exit /B
:Done
XCopy "<Source>" "%_target%" /<Options>
Upvotes: 0
Reputation: 56155
Why opening every possible drive letter?
for /f "tokens=2 delims==:" %%a in ('wmic logicaldisk where volumename^="Philips" get name /value') do set "volume=%%a:"
echo your volume is %volume%
Note: I used one of several possible tricks to avoid the ugly wmic
line endings.
Upvotes: 0
Reputation:
You can try this:
@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 (
vol %%a:
for /f "tokens=1-5*" %%1 in ('vol %%a:') do (
if "%%6"=="Philips" set "vol=%%6"
)
)
echo I found: %vol%
Where you will replace echo I found: %vol%
with your actual commands.
Upvotes: 1