Simplify 3 lines of Code
Posted: 08 Jan 2014 21:35
I've got this script that finds the drive letter which my external USB is connected to based upon the drive label, Seagate.
somehow wmic creates a unicode text file which can't be read as easy as a straight text file, so that's why I have 3 lines, 2 of which write to a file in the temp directory.
Is there a better way, short and simple to find the drive letter of my external drive based upon the drive label, Seagate, without writing a temp file to disk?
the drive letter needs to be found and set to variable based about the drive label, Seagate
Scenario, When going portable, the drive once connected to my other workstation across town will pick up the external drive but set it to a different drive letter.
This is for automating backups.
thank you for your consideration and support,
v/r Booga73
tmp.txt shows the following data:
tmp2.txt shows the following data:
My code output is showing:
somehow wmic creates a unicode text file which can't be read as easy as a straight text file, so that's why I have 3 lines, 2 of which write to a file in the temp directory.
Is there a better way, short and simple to find the drive letter of my external drive based upon the drive label, Seagate, without writing a temp file to disk?
the drive letter needs to be found and set to variable based about the drive label, Seagate
Scenario, When going portable, the drive once connected to my other workstation across town will pick up the external drive but set it to a different drive letter.
This is for automating backups.
thank you for your consideration and support,
v/r Booga73
Code: Select all
wmic logicaldisk get Name,VolumeName /Format:csv > %tmp%\TMP.txt
more +2 %tmp%\tmp.txt > %tmp%\tmp2.txt
for /f "tokens=2 delims=," %c in ('findstr Seagate %tmp%\tmp2.txt') do @echo %c
tmp.txt shows the following data:
Code: Select all
Node,Name,VolumeName
BatchNoob,C:,
BatchNoob,D:,Archive Drive
BatchNoob,E:,Win7x64Rec
BatchNoob,F:,iRT Drive
BatchNoob,G:,WSTDGT Drive
BatchNoob,I:,Seagate
BatchNoob,J:,irtDiag
BatchNoob,K:,
BatchNoob,L:,
tmp2.txt shows the following data:
BatchNoob,C:,
BatchNoob,D:,Archive Drive
BatchNoob,E:,Win7x64Rec
BatchNoob,F:,iRT Drive
BatchNoob,G:,WSTDGT Drive
BatchNoob,I:,Seagate
BatchNoob,J:,irtDiag
BatchNoob,K:,
BatchNoob,L:,
My code output is showing:
I: