Sign in to follow this  
Followers 0
redfive19

Get Drive Letter according to label

11 posts in this topic

Hello all,

Here's what I want to do. I want to scan all the drives in my system ('ALL') and look for particular drive labels. When I find that drive label, I want to return the drive letter it is associated with. I know that this involves using DriveGetDrive and DriveGetLabel but I can't wrap my head around For - Next. I need it to find TWO partitions and return TWO different ones. In this case, one partition will always be labeled 'Image' and one will always be labeled 'Transfer'.

Any ideas? Sorry if it's been asked before, I searched but couldn't find an answer to it.

Thanks ahead of time!

-redfive

Share this post


Link to post
Share on other sites



HI,

try this:

MsgBox(0, "", getDrive("transfer"))
MsgBox(0, "", getDrive("image"))

Func getDrive($label = "Windows")
    $var = DriveGetDrive( "all")
    If Not @error Then
        For $i = 0 To $var[0]
            If DriveGetLabel($var[$i] & "\") = $label Then
                Return $var[$i]
            EndIf
        Next
    EndIf
EndFunc  ;==>getDrive

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

MsgBox(0, "", getDrive("transfer"))
MsgBox(0, "", getDrive("image"))

Func getDrive($label = "Windows")
    $var = DriveGetDrive( "all")
    If Not @error Then
        For $i = 0 To $var[0]
            If DriveGetLabel($var[$i] & "\") = $label Then
                Return $var[$i]
            EndIf
        Next
    EndIf
EndFunc;==>getDrive
And why $var[$i] & "\" ?

For $i = 0 To $var[0]
   If DriveGetLabel($var[$i]) = $label Then
      Return StringUpper($var[$i])
   EndIf
Next

Works just as well

BTW StringUpper($var[$i]) is to make it pretty :)

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

hmmm this isn't working. It's returning '0' for every drive. Any ideas?

Share this post


Link to post
Share on other sites

nvm took the '& "\"' and it's returning them now. Thanks!

Share this post


Link to post
Share on other sites

nvm took the '& "\"' and it's returning them now. Thanks!

HI,

??? That is what i gave you. Only added the StringUpper ...

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

HI,

??? That is what i gave you. Only added the StringUpper ...

So long,

Mega

I think he's saying that he removed the ( & "\"). Although either method still returned the same result for me, I could forsee a possible problem on some systems when using it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Now I am trying to figure out how to parse a DISKPART log file. Either of you guys ever done that?

Share this post


Link to post
Share on other sites

Now I am trying to figure out how to parse a DISKPART log file. Either of you guys ever done that?

Post part of the log file and the file name and I'll have a look at it. I don't even see a diskpart log on mine but I could be looking for the wrong file.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Microsoft DiskPart version 5.1.3565

Copyright (C) 1999-2003 Microsoft Corporation.
On computer: WUS1ZR9W91

Disk 1 is now the selected disk.

SAMSUNG MP0402H USB Device
Disk ID: CB93144C
Type   : USB
Bus : 0
Target : 0
LUN ID : 0

  Volume ###  Ltr  Label        Fs   Type       Size     Status  Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 3   J   Images    NTFS   Partition  24 GB  Healthy         
  Volume 4   K   Transfer    NTFS   Partition    13 GB  Healthy         

Microsoft DiskPart version 5.1.3565

ADD      - Add a mirror to a simple volume.
ACTIVE    - Marks the current basic partition as an active boot partition.
ASSIGN    - Assign a drive letter or mount point to the selected volume.
BREAK      - Break a mirror set.
CLEAN      - Clear the configuration information, or all information, off the
              disk.
CONVERT  - Converts between different disk formats.
CREATE    - Create a volume or partition.
DELETE    - Delete an object.
DETAIL    - Provide details about an object.
EXIT        - Exit DiskPart
EXTEND    - Extend a volume.
HELP        - Prints a list of commands.
IMPORT    - Imports a disk group.
LIST        - Prints out a list of objects.
INACTIVE    - Marks the current basic partition as an inactive partition.
ONLINE    - Online a disk that is currently marked as offline.
REM      - Does nothing. Used to comment scripts.
REMOVE    - Remove a drive letter or mount point assignment.
REPAIR    - Repair a RAID-5 volume.
RESCAN    - Rescan the computer looking for disks and volumes.
RETAIN    - Place a retainer partition under a simple volume.
SELECT    - Move the focus to an object.

Share this post


Link to post
Share on other sites

Parsing DiskPart is a pain, but it can be done.

Code samples, though they probably are not very readable

http://www.autoitscript.com/forum/index.ph...7844&hl=diskpat

http://www.autoitscript.com/forum/index.ph...704&hl=diskpart


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0