Page 1 of 1

Save to USB memory stick

Posted: 23 Feb 2011 03:08
by atamo
Hy

I want to save my daily works from a folder named TODAY to a folder called today's date for example 28.02.2011 created on USB Memory Stick.
The big problem is that the Stick Drive letter is sometime H:, sometime K:, sometime I: >>>>> so I dont know the Stick Drive Letter...:(

I want to write this commands in a bat file but unfortunately I don't know the Stick drive letter... :?:

I appreciate any help.

thank's

Re: Save to USB memory stick

Posted: 23 Feb 2011 08:57
by !k

Code: Select all

@Echo Off
setlocal EnableDelayedExpansion

Set "Source=TODAY"

Set /A Cnt=0&For /F "Tokens=2 Delims==" %%A In (
'WMIC LogicalDisk Where ^(DriveType^=2 And MediaType^=NULL^) Get Name /Value'
) Do (Set /A Cnt+=1&Set Usb!Cnt!=%%A&Echo.!Cnt!. Copy to drive %%A)
Echo.&Set /P "Number=Please, enter the number "
Set Usb%Number% >nul 2>&1&&Call xCopy /S /I /Y "%Source%" !Usb%Number%!\%date%||Echo Wrong number. Try again.
endlocal

Re: Save to USB memory stick

Posted: 15 Mar 2011 12:44
by atamo
thank's !k the great HELP


Because MediaType for USB can be 0, 11 or sometime null , I want to use for filter deviceID<>'A:'

Code: Select all

wmic logicaldisk where (drivetype=2 and deviceID^<^>'A:') get deviceID 
work nice, return>>

DeviceID
P:

but I need only second line ,and the bottom code don't work :? (Of course later I change the ECHO command with SET myUSBdriveIs=%i)

Code: Select all

for /f "skip=1" %i IN ('wmic logicaldisk where ^(drivetype^=2 and deviceID^<^>'A:'^) get deviceID') Do (Echo %i)
return

>was unexpected at this time.


what's wrong with this code :?:

Re: Save to USB memory stick

Posted: 15 Mar 2011 13:17
by !k

Code: Select all

for /f "skip=1" %i IN ('wmic logicaldisk where ^(drivetype^=2 and deviceID^^^<^^^>'A:'^) get deviceID') Do (Echo %i)

Re: Save to USB memory stick

Posted: 15 Mar 2011 13:48
by atamo
unfortunately

') was unexpected at this time

:(

Re: Save to USB memory stick

Posted: 15 Mar 2011 14:52
by !k
Hmm :? it works for me

Try

Code: Select all

for /f "skip=1" %i IN ('wmic logicaldisk where ^(drivetype^=2 and deviceID^^^<^^^>^'A:^'^) get deviceID') Do (Echo %i)
or

Code: Select all

for /f "usebackq skip=1" %i IN (`wmic logicaldisk where ^(drivetype^=2 and deviceID^^^<^^^>'A:'^) get deviceID`) Do (Echo %i)

Re: Save to USB memory stick

Posted: 16 Mar 2011 07:50
by atamo
with usebackq option work nice, Thank's Again :P