Computing.Net > Forums > Programming > Batch file commands & drive labels

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file commands & drive labels

Reply to Message Icon

Name: Mike Ommand
Date: January 8, 2009 at 09:34:26 Pacific
OS: Windows XP
CPU/Ram: Pent4 2GB
Product: Self build / SELF BUILT
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 8, 2009 at 11:15:50 Pacific
Reply:

:: 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


0

Response Number 2
Name: Mike Ommand
Date: January 9, 2009 at 06:07:57 Pacific
Reply:

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


0

Response Number 3
Name: Mike Ommand
Date: January 9, 2009 at 08:11:33 Pacific
Reply:

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


0

Response Number 4
Name: Mechanix2Go
Date: January 10, 2009 at 01:49:39 Pacific
Reply:

@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


0

Response Number 5
Name: Mike Ommand
Date: January 12, 2009 at 13:28:21 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file commands & drive labels

batch file command? www.computing.net/answers/programming/batch-file-command/13574.html

Batch file commands help ! www.computing.net/answers/programming/batch-file-commands-help-/16201.html

Simple Batch File command help www.computing.net/answers/programming/simple-batch-file-command-help/16568.html