Jump to content

get drives


seres
 Share

Recommended Posts

Look at the functions DriveGetDrive and DriveGetType in the documentation to handle this issue.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Look at the functions DriveGetDrive and DriveGetType in the documentation to handle this issue.

in DriveGetDrive how do i exclude the cdrom drive

Type of drive to find:

"ALL", "CDROM", "REMOVABLE", "FIXED", "NETWORK", "RAMDISK", or "UNKNOWN"

DriveGetDrive ( "type" )

Link to comment
Share on other sites

in DriveGetDrive how do i exclude the cdrom drive

Type of drive to find:

"ALL", "CDROM", "REMOVABLE", "FIXED", "NETWORK", "RAMDISK", or "UNKNOWN"

DriveGetDrive ( "type" )

Hi,

just loop over the returned array by DriveGetDrive ("All") with DriveGetType.

;-))

Stefan

Link to comment
Share on other sites

Look up the documentation on For and While under Keywords.

Local $I
Local $aDrives = DriveGetDrive("ALL"); Get an array of connected drives.

For $I = 0 To UBound($aDrives)-1
    Switch DriveGetType($aDrives[$I])
    Case "NETWORK"
        ; Do what you want for network drives here.
    Case "CDROM"
        ; Do what you want to do to cd-roms'
    EndSwitch
Next

So while you are looking up loops, you might also want to look up Switch and UBound as well.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

  • 2 weeks later...

Look up the documentation on For and While under Keywords.

Local $I
Local $aDrives = DriveGetDrive("ALL"); Get an array of connected drives.

For $I = 0 To UBound($aDrives)-1
    Switch DriveGetType($aDrives[$I])
    Case "NETWORK"
        ; Do what you want for network drives here.
    Case "CDROM"
        ; Do what you want to do to cd-roms'
    EndSwitch
Next

So while you are looking up loops, you might also want to look up Switch and UBound as well.

hello, i tried this method, and its great, i get a problem when the a drive since i have no disk inside windows returns me an error here is my code

Local $I
Local $aDrives = DriveGetDrive("ALL"); Get an array of connected drives.

while 1
For $I = 0 To UBound($aDrives)-1
    Switch DriveGetType($aDrives[$I])
        Case "Removable"
        If FileExists($aDrives[$I] & "\newdoc.txt")  Then

        
    EndIf       
    
    EndSwitch
Next
wend
Link to comment
Share on other sites

  • 7 months later...

hello, i tried this method, and its great, i get a problem when the a drive since i have no disk inside windows returns me an error here is my code

Local $I
Local $aDrives = DriveGetDrive("ALL"); Get an array of connected drives.

while 1
For $I = 0 To UBound($aDrives)-1
    Switch DriveGetType($aDrives[$I])
        Case "Removable"
        If FileExists($aDrives[$I] & "\newdoc.txt")  Then

        
    EndIf       
    
    EndSwitch
Next
wend

I don't know if anyone got back to you but you should also include for removable, network, etc. drives to use DriveGetStatus to check if they are available or else your program will throw an error when you try to access the disk that doesn't exist or has issues.

Link to comment
Share on other sites

#include <File.au3>

$Drives = DriveGetDrive("ALL")
Global $DriveArray[$Drives[0]][8]

For $X = 0 To $Drives[0]-1
    $DriveArray[$X][0] = StringUpper($Drives[$X+1])
    $DriveArray[$X][1] = DriveGetFileSystem($Drives[$X+1] & "\")
    If $DriveArray[$X][1] = "" Then $DriveArray[$X][1] = "<NO FILESYSTEM>"
    $DriveArray[$X][2] = DriveGetLabel($Drives[$X+1] & "\")
    If $DriveArray[$X][2] = "" Then $DriveArray[$X][2] = "<NO LABEL>"
    $DriveArray[$X][3] = DriveGetSerial($Drives[$X+1] & "\")
    If $DriveArray[$X][3] = "" Then $DriveArray[$X][3] = "<NO SERIAL>"
    $DriveArray[$X][4] = DriveStatus($Drives[$X+1] & "\")
    If $DriveArray[$X][4] = "" Then $DriveArray[$X][4] = "<NO STATUS>"
    If $DriveArray[$X][4] = "NOTREADY" Then $DriveArray[$X][4] = "<NOT READY>"
    $DriveArray[$X][5] = Round(DriveSpaceFree($Drives[$X+1] & "\"))
    If $DriveArray[$X][5] = "" Then $DriveArray[$X][5] = "<NO FREE SPACE>"
    $DriveArray[$X][6] = Round(DriveSpaceTotal($Drives[$X+1] & "\"))
    If $DriveArray[$X][6] = "" Then $DriveArray[$X][6] = "<NO TOTAL SPACE>"
    $DriveArray[$X][7] = Round($DriveArray[$X][6] - $DriveArray[$X][5])
    If $DriveArray[$X][7] = "" Then $DriveArray[$X][7] = "<NO REMAINING SPACE>"
    ConsoleWrite($DriveArray[$X][0] & @CRLF)
Next

;Write information to file
FileWrite("Drive_Log.txt", "DATE: " & @MDAY & "\" & @MON & "\" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
FileWrite("Drive_Log.txt", "-------------------------------------------------------------------------------" & @CRLF & @CRLF)
_WriteArrayToFile("Drive_Log.txt", $DriveArray)
FileWrite("Drive_Log.txt", "-------------------------------------------------------------------------------" & @CRLF & @CRLF)

;Write multi-dimensional array to file
Func _WriteArrayToFile($Path, $Array)
    Local $File = FileOpen($Path, 1)

    For $Row = 0 To Ubound($Array)-1
        FileWrite($File, $Array[$Row][0] & @CRLF)

        For $Column = 1 To UBound($Array, 2)-1
            FileWrite($File, "|" & $Array[$Row][$Column] & @CRLF)
        Next
        FileWrite($File, @CRLF)
    Next

    FileClose($File)
EndFunc

I made this a while back. Dumps all drive information to a file.

Edited by darkjohn20
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...