Sign in to follow this  
Followers 0
Diana (Cda)

Get drive letter and label?

7 posts in this topic

#1 ·  Posted (edited)

I don't know what I did wrong but after searching forum and help file found DriveGetLabel. The script I made is showing up blank despite the fact that all my drives have labels.

What did I do wrong here, pls?:

;================================================
$var = DriveGetLabel(@ScriptDir & "\")
;================================================
MsgBox(4096,"Volume Label: ","The drive label is:  " & $var & "       ")

Further, it would be nice for the message box to have the output like this:

D = UFD

p.s., When I put the actual drive letter in ("D:" instead of "@ScriptDir & "\""), I got the desired output of "UFD" but I'd prefer to use @ScriptDir so that this one script works in any folder to know what the root volume drive letter and volume are.

Thanks! :huh2:

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you must indicate Path of drive to receive information from.

Like c:\ or D:\ ..

you can see for _PathSplit function.

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Then you should perhaps take a look at the requirements for DriveGetLabel() and the return of @ScriptDir.

Try this instead

$var = DriveGetLabel(StringLeft(@ScriptDir, 2))

EDIT"

Also this one

$var = DriveGetLabel(StringLeft(@ScriptFullPath, 2))
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

Then you should perhaps take a look at the requirements for DriveGetLabel() and the return of @ScriptDir.

Try this instead

$var = DriveGetLabel(StringLeft(@ScriptDir, 2))

EDIT"

Also this one

$var = DriveGetLabel(StringLeft(@ScriptFullPath, 2))

Oh, okay. I don't understand why what you did with DriveGetLabel works rather than just with the command but the good thing is that they both work! <vbg> Thanks. They don't give the drive letter but they give the volume name, which is great. I have 2 folders I open up with a script that are identical, just that one is on the hdd and the other on the usb stick. With the script the drive label will help me know at a glance which one I'm on. I prefer to work on the financials on the hdd and then copying them over to the usb stick rather than vice versa.

Thanks. :huh2:

---------------------

p.s., to get the drive letter to also be displayed, what command would we use, pls? Is there anything?

If there is a way, I'd then use this script:

;================================================
$var = DriveGetLabel(StringLeft(@ScriptDir, 2))
;================================================
MsgBox(4096,"Volume Label: ","The drive is:  " & @CRLF & @CRLF & [drive letter] & " = " & $var & "       ")

where [drive letter] would be where that AutoIt command would go.

Just out of curiousity.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Func _ExtractDriveFromPath($vPath)
    Return StringLeft($vPath, 2)
EndFunc

Unless of course you want me to get fancy and do it with StringRegExpReplace() and an extra parameter to include the back-slash (or not).

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

Here another method using WMI:

;coded by UEZ 2011
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_UseUpx=n
#include <Array.au3>

$oMyError = ObjEvent("AutoIt.Error", "oMyError") ; Install a custom error handler

Global $ip = "localhost"
If $CmdLine[0] > 0 Then $ip = $CmdLine[1]

$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2")

$aMyDriveLabels = GetWMI($ip)
_ArrayDisplay($aMyDriveLabels)

Func GetWMI($srv)
    Local $DriveLabel, $sDriveLabels, $i
    Local $aDriveLabels[26][2]
    $colItems = $objWMIService.ExecQuery("SELECT Name, VolumeName FROM Win32_LogicalDisk", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $aDriveLabels[$i][0] = $objItem.Name
            $aDriveLabels[$i][1] = $objItem.VolumeName
            $i += 1
        Next
    EndIf
    ReDim $aDriveLabels[$i][2]
    Return $aDriveLabels
EndFunc

Func oMyError()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.Description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.WinDescription & @CRLF & _
             "err.number is: "         & @TAB & Hex($oMyError.Number, 8) & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.LastDllError   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.Scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.Source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.Helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.HelpContext _
            )
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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