Hello daniweb members,

I hope you can assist me... My apologies for very rusty DOS knowledge.
The batch file I'm trying to write must...
... recognize which drive letter has been assigned by Windows to ONE USB memory stick
... format it according to very precise instructions.

So I've determined ...
A) how to display the drive information,
B) how to format the drive properly...

but I cannot close the gap between A and B. I don't remember how to make "b" understand which drive it should format:

A

@echo off
setlocal enabledelayedexpansion
set UsbNum=0
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 (
  for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
    set /a UsbNum+=1
    set DriveU!UsbNum!=%%h
  )
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
  echo.!DriveU%%a!
)
endlocal
pause

B ("e:" is just there for the example)

format e: /x /fs:FAT /v:FORMATHISDRIVE_H12

In A starting in your last loop under your echo.!DriveU%%a!:

set thdrive=!DriveU%%a!
)
echo format %thdrive% /x /fs:FAT /v:FORMATHISDRIVE_H12>formatit.bat
call formatit.bat
del /f formatit.bat
endlocal
pause
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.