Jump to content

find driveletter by known subdir?


sph0x
 Share

Recommended Posts

hello there!

i'm not very good in using autoit, so i hope to get some help here: all i need is a function to get the driveletter from an usb-drive.

i want to start and stop some programms on a usb-device via autoit - and i want to do this on many different computers, so the drive-letter to the applications is changing all the time. even on one single machine the driveletter is not constant, sometimes i have to change it manually (xp-thingy), sometimes the network-admin is messing around and network devices change their letter....

whatsoever, i don't want to do a simple search for the .exe-files, this would take too much time. so i thought about searching a pattern like "*\myknownfolder\", because the "myknownfolder" (of course) exists on the usb-device, and by locating it i thought i could get the matching driveletter from the search result.

this does not sound very difficult, but i cant get this thing working.

here is what i tried so far:

$var = DriveGetDrive( "all" )

If NOT @error Then

    For $i = 1 to $var[0]      
                
        $search = FileFindFirstFile ( $var[i] & "\myknownfolder")
        
        If Not $search = -1 Then
            $usb = $var[i]
        EndIf

        FileClose($search)        

    Next
              
        MsgBox(4096, "Found Driveletter:", $usb)

EndIf

does anyone know how to get this working? or, if i'm completely wrong here - does anyone know how to manage a function like this?

thank you for reading - and for all helpfull answers,

nice weekend,

sph

Link to comment
Share on other sites

Does this work better?

$var = DriveGetDrive( "all" )
$usb="Not found"
If NOT @error Then
    For $i = 1 to $var[0]       
        $search = FileExists( $var[$i] & "\Scripts")
        If $search Then
            $usb = $var[$i]
            ExitLoop
        EndIf      
    Next 
        MsgBox(4096,"", "Found Driveletter: "& StringUpper($usb))
EndIf

You could also try: DriveGetDrive ( "REMOVABLE" ) for USB disks.

Edited by Nahuel
Link to comment
Share on other sites

YES, a whole lot better - thank you very much! <_<

You could also try: DriveGetDrive ( "REMOVABLE" ) for USB disks.

yes, but some of my usb-stuff is mounted via truecrypt, and so it's not recognized as a removable drive, that's why i guess "all" would work better.

so, your script works, it shows me the driveletter as wanted - but there is another thing: i get an annoying error-message, i think it comes when the script tries to search the a:\ directory, when no floppy disc is inserted. is there a way to exclude the a:-drive?

thanks alot,

bye!

Link to comment
Share on other sites

Yes, I had the same problem. Try this:

$var = DriveGetDrive( "all" )
$usb="Not found"
If NOT @error Then
    For $i = 1 to $var[0]   
        If  $var[$i]<>"a:" Then
            $search = FileExists( $var[$i] & "\Scripts")
            If $search Then
                $usb = $var[$i]
                ExitLoop
            EndIf      
        EndIf
    Next 
        MsgBox(4096,"", "Found Driveletter: "& StringUpper($usb))
EndIf
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...