Jump to content

Finding a file


Recommended Posts

Hi all

Is there a way of finding a file on a mapped drive...the problem is it could be mapped to any drive letter as there hasnt been any standardisation.

I cant find any thing in the help files other than FileExists which seems to need a drive letter to be specified.

Thanks

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

You could use DriveGetDrive("network") to get a list of network drive letters.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Thanks for this (I think )

Whats the deal with DriveGetDrive......

I cant even get it to write a single drive letter to a file, never mind all network drives.

$drive = DriveGetDrive("Network")

FileWrite("c:\drive.txt", $drive)

Am I missing something SOOOOO obvious here, if I change the variable it writes no problem but with DriveGetDrive it creates the file but doesnt write to it.... :D

Thanks

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

  • Moderators

Thanks for this (I think )

Whats the deal with DriveGetDrive......

I cant even get it to write a single drive letter to a file, never mind all network drives.

$drive = DriveGetDrive("Network")

FileWrite("c:\drive.txt", $drive)

Am I missing something SOOOOO obvious here, if I change the variable it writes no problem but with DriveGetDrive it creates the file but doesnt write to it.... :D

Thanks

Maybe read the documentation :D ?

Success: Returns an array of strings (drive letter followed by colon) of drives found. The zeroth array element contains the number of drives.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks for this SmOke_n...

I understand that this is the issue but I'm not a programmer and I've only been using AutoIt for about a month so it's a bit like the "You're in a helicopter" Microsoft joke.

I need to be able to use the information as per my post, but I cant even find a start point in the help files and there isnt any other way I can see for me to learn. I dont want anyone to do the work, I want to do it myself so I can learn but its very difficult with the info I've got.

I know I'm relying on the good nature of people with more knowledge than me but hopefully it time I will be able to learn and help people too....altruism is wonderful thing

Sorry if this sounds feeble but I'm just a mere mortal

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

  • Moderators

Thanks for this SmOke_n...

I understand that this is the issue but I'm not a programmer and I've only been using AutoIt for about a month so it's a bit like the "You're in a helicopter" Microsoft joke.

I need to be able to use the information as per my post, but I cant even find a start point in the help files and there isnt any other way I can see for me to learn. I dont want anyone to do the work, I want to do it myself so I can learn but its very difficult with the info I've got.

I know I'm relying on the good nature of people with more knowledge than me but hopefully it time I will be able to learn and help people too....altruism is wonderful thing

Sorry if this sounds feeble but I'm just a mere mortal

See if this helps:
$drive = DriveGetDrive("Network")
If Not @error Then 
    For $i = 1 To UBound($drive) - 1
        FileWriteLine(@HomeDrive & "\drive.txt", $drive[$i])
    Next
Else
    MsgBox(64, 'Info:', 'No Drives Found')
EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi and thanks for this, it gives me a bit of an insight although I dont fully understand what some of the bits do.

Is there a way that I can check these drives for a specific file without writing the drives to a file. I can do it from a file but it seems like a clumsy way of doing it.

I am trying to establish which machines have got a mapped drive to a particular share but there is no drive letter uniformity. If it is possible can you point me in the right direction, as I say I dont expect or want people to do the work -I just need a gentle shove.

Thanks for your time so far and your help

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

  • Moderators

I'm not sure about the "NETWORK" thing as I can't test it, and I had to use "A:" for the Floppy Drive so I didn't get an error, but this seemed to be efficient:

Local $drive = DriveGetDrive("NETWORK"), $FileLocationName = '\Program Files'
If Not @error Then 
    For $i = 1 To UBound($drive) - 1
        If $drive[$i] <> 'A:' And FileExists($drive[$i] & $FileLocationName) Then 
            MsgBox(64, 'Info:', 'The File was found on ' & $drive[$i] & ' drive.')
        EndIf
    Next
Else
    MsgBox(64, 'Info:', 'No Drives Found')
EndIf
Maybe you can mod it.

To understand what was done, DriveGetDrive returns an array of information on drives that were found [0] will tell you the amount of drives found, and [1], [2], [3] etc... contain return arrays element values. The For/Next Loop and $i is used to go through each option so you'll see 1 To Ubound($drive) - 1 (Ubound has the total elements (drives) found like [0]), so $i = 1 the first loop, 2 the sencond loop, 3 the third loop etc... so [$i] results in [1], [2], [3] etc...

Hope that sheds some light.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

HI,

do you know the label of the drive to get a bit less search options. You could compare the label.

Just an idea.

$drive = DriveGetDrive("NETWORK")
If Not @error Then
    For $i = 1 To UBound($drive) - 1
        ConsoleWrite($i & " " & $drive[$i] & " " & DriveGetLabel($drive[$i]) & @CR)
    Next
Else
    MsgBox(64, 'Info:', 'No Drives Found')
EndIf

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

Link to comment
Share on other sites

Or try running this; 2 ways to look at it;

;DriveMapgetExample.au3
local $s_Line
$drive = DriveGetDrive("NETWORK")
If Not @error Then
    MsgBox(0,"","number odf drives="&$drive[0])
    MsgBox(0,"","number odf drives="&UBound($drive)-1)
    For $i = 1 To UBound($drive) - 1
        $s_Line&=$drive[$i]&@CRLF
    Next
    ;FileWrite(@HomeDrive & "\drive.txt", $s_Line)
    MsgBox(64, 'Info:', $s_Line)
Else
    MsgBox(64, 'Info:', 'No Drives Found')
EndIf
;OR;
; Get details of the mapping
for $i=1 to 26
    $s_DriveLetter=chr(64+$i)
    $s_MyDriveMapGet=DriveMapGet( $s_DriveLetter&":")
    if not @error then
        MsgBox(0, "Drive "&$s_DriveLetter&": is", $s_DriveLetter&":")
        MsgBox(0, "Drive "&$s_DriveLetter&": is mapped to", $s_MyDriveMapGet)
    EndIf
next
Randall
Link to comment
Share on other sites

Hi there

Thank you soo much for your help...it really is very much appreciated.

SmOKe_N: it works really well, thanks for the code but thanks even more for the explanation..that's far more valuable to me. Thanks for your help AND your patience.

Mega: Thanks for your input too, as per my posts in this thread any info is greatly appreciated and this is yet another way of looking at the situation.

Randall: As above with Mega, thanks

Thanks once again all for your help

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

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...