Batch file commands & drive labels

Self build / SELF BUILT
January 8, 2009 at 09:34:26
Specs: Windows XP, Pent4 2GB
Hi,
I'm trying to configure a number of USB drives, using the Windows command prompt.
The 1st part of the config will convert the existing file system from FAT32, to NTFS, then install some files, then run a quick "chkdsk".
This all works fine from a batch file.
The problem is that I need to run this on 10 drives at a time, and that as I attach the drives via USB, Windows will sometimes miss out drive letters (the batch file works using these drive letters).
All USB drives start with the same drive lable. The only difference is that the label ends with the drive size.
Does anyone know if there is a command that will work in a batch file, that will look for a drive lable, and not the drive letter?
Something like:
IF DRIVE LABEL(drive size)=XXX, THEN RUN XXXX.BAT.
Many thanks.

See More: Batch file commands & drive labels

Report •


#1
January 8, 2009 at 11:15:50
:: find drive by label

@echo off & setLocal EnableDelayedExpansion

for %%a in (d e f g h i j k l m n) do (
for /f "tokens=6 delims= " %%i in ('vol %%a: ^|find "drive"') do (
echo %%i | find "my label prefix" > nul
if not errorlevel 1 echo process drive %%a:
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
January 9, 2009 at 06:07:57
Hi Mechanix2Go,
That seems to work lovely. Thank you very much.
Unfortunately, due to my lack of knowledge, or stupidity even, I’ve got stuck.
If I run the script you have supplied, I need it to run the various tasks on the drives found.
For example…If I set your script to find drives with a label of “disk”, this works fine. If I then want to run a CheckDisk on the drive found, I would put something like:
Chkdsk F: /I/F (where drive F:, is the drive found).
As F: is going to be a variable, how would I instruct chkdsk to run on this variable?
Kind regards,
Mike

Report •

#3
January 9, 2009 at 08:11:33
Ahh, I now have the chkdsk option working. But I also have another issue (I don't think this is fixable).
I need to run a program that converts the FAT file system to NTFS, then install files to the drive, then verifies them. It goes something like:
"C:\program name.exe /target=D:"
Any idea have I could substitute the D:, for the variable?
If there is a limitation with the .exe file, I may be stuck.
Cheers,
Mike

Report •

Related Solutions

#4
January 10, 2009 at 01:49:39
@echo off & setLocal EnableDelayedExpansion

for %%a in (d e f g h i j k l m n) do (
for /f "tokens=6 delims= " %%i in ('vol %%a: ^|find "drive"') do (
echo %%i | find "mylabel" > nul
if not errorlevel 1 call :sub1 %%a:
)
)

goto :eof

:sub1
:: * to activate take out the ECHOs below

echo chkdsk %1
echo convert %1
echo "C:\program name.exe /target=D:"

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
January 12, 2009 at 13:28:21
Hi Mechanix2Go,
Took me ages to get it to work, but the final part you provided, did the trick
I’ll have to sit down and read the help pages, to see if I can work out what you have given me.
Many thanks,
Mike

Report •


Ask Question