JLC123 Posted November 14, 2004 Share Posted November 14, 2004 I'm thinking (or maybe hoping) that no one has answered my previous post because I added to an older post. Sorry, but emmanuel hasn't been active on the board for about a month or more.<{POST_SNAPBACK}>I need to:- gather a list of network drives- check to see if one of them is mapped to \\server\myserver- check to see what drive letters are not mapped and therefore available- if no dirve is mapped to \\server\myserver ask the user to select from the list of available drive letters and map it for them.I have acomplished:- gathered the list and piped it to a text file (maybe sending it to a text file isn't necessary, but I wanted to "see" it and I'm a batch file person and wanted to "findstr") Can't seem to acomplish:- is any drive letter mapped to \\server\myserver?- if not what drive letters are available?Any help please? Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
Developers Jos Posted November 14, 2004 Developers Share Posted November 14, 2004 (edited) Can't seem to acomplish:- is any drive letter mapped to \\server\myserver?- if not what drive letters are available?Any help please?<{POST_SNAPBACK}>just a couple of ideas:- use the DriveGetDrive ( "all" ) to find the drive letters in use.- here is a script to list all mapped network drives (need 3.0.103 unstable):$var = DriveGetDrive( "network" ) If NOT @error Then MsgBox(4096,"", "Found " & $var[0] & " drives") For $i = 1 to $var[0] MsgBox(4096,"Drive " & $i, DriveMapGet($var[$i])) Next EndIf Edited November 14, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JLC123 Posted November 14, 2004 Author Share Posted November 14, 2004 (edited) Still can't get the search to do what I need. Here's the text file the code creates: G: is mapped to \\someserver\notmine H: is mapped to \\someserver\yours I: is mapped to \\server\wrongone J: is mapped to \\server\myserver Here's the code I'm trying to use. What I want is if anything is mapped to \\server\myserver just move on - if not return the result that it's "not mapped" FileOpen("c:\temp\map.txt", 0) If StringInStr("c:\temp\map.txt", "\\server\myserver")=0 Then MsgBox(1,"","not mapped") EndIf Once I get past that, if it's not mapped properly, I need to find an available drive to use to DriveMapAdd("$var", "\\server\myserver") Edited November 14, 2004 by JLC123 Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
Developers Jos Posted November 14, 2004 Developers Share Posted November 14, 2004 (edited) you are not reading the file... try this (Untested): $HFile = FileOpen("c:\temp\map.txt", 0) ; test here is successfull ; read file into variable $Trecs=FileRead($HFile, FileGetSize($SFilepath)) If StringInStr($Trecs, "\\server\myserver")=0 Then MsgBox(1,"","not mapped") EndIf Edited November 14, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JLC123 Posted November 14, 2004 Author Share Posted November 14, 2004 Thank you! That worked, but I don't quite understand why. I understand that I wasn't reading the file, but why do I need to know the file size? Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
scriptkitty Posted November 15, 2004 Share Posted November 15, 2004 (edited) FileRead()FileRead --------------------------------------------------------------------------------Read in a number of characters from a previously opened text file.FileRead ( filehandle or "filename", count )Parametersfilehandle The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter. count The number of characters to read.You would want to read the whole file, so you should know how big it is in order to read all of it.On a side note, you don't actually have to open it. ("previously opened")You can just FileRead without opening it, same as FileWriteLine.This will work, $Hfile="c:\temp\map.txt" $Trecs=FileRead($HFile, FileGetSize($Hfile)) If StringInStr($Trecs, "\\server\myserver")=0 Then MsgBox(1,"","not mapped") EndIf Edited November 15, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
JLC123 Posted November 15, 2004 Author Share Posted November 15, 2004 Thanks Scriptkitty! I Need to understand the code, not just cut and paste, or I'll be posting "help" requests forever! (and, no one wants that!) And on a side note of my own, I've learned a few things from your posts here, so thanks again and keep up the good work! Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
scriptkitty Posted November 15, 2004 Share Posted November 15, 2004 ok, a bit of explanation. $Hfile="c:\temp\map.txt" ; sets the name into a variable $Trecs=FileRead($HFile, FileGetSize($Hfile)) ; give the varable $Trecs the entire file by reading the size and then knowing ; the size, reads the full file If StringInStr($Trecs, "\\server\myserver")=0 Then ; if string is found inside variable then MsgBox(1,"","not mapped") ; this displays a msg EndIf ; finishes the If statement AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
JLC123 Posted November 15, 2004 Author Share Posted November 15, 2004 What's wrong with this syntax? Having trouble with my loops $file = "c:\temp\map.txt" $HFile = FileOpen($file, 0) $RFile=FileRead($HFile, FileGetSize($file)) If StringInStr($RFile, "\\server\myserver")=0 Then While 1 $mapto = InputBox("Not mapped to server\myserver", "Current drive mappings are as follows:" & @CRLF & "" & @CRLF & $RFile & @CRLF & "Please select an available drive letter, the application will map to server\myserver for you" & @CRLF & "" & @CRLF & "(Do not select M or N please)", "", "", "", 351) EndIf If $mapto = "M" Or "N" Then $bad = MsgBox(0, "Invalid drive specification", "You have entered an invalid drive" & @CRLF & "Please try again") EndIf DriveMapAdd($mapto) WEnd Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
Developers Jos Posted November 15, 2004 Developers Share Posted November 15, 2004 What's wrong with this syntax? Having trouble with my loops<{POST_SNAPBACK}>Ouput from Tidy:$file = "c:\temp\map.txt" $HFile = FileOpen($file, 0) $RFile = FileRead($HFile, FileGetSize($file)) If StringInStr($RFile, "\\server\myserver") = 0 Then While 1 $mapto = InputBox("Not mapped to server\myserver", "Current drive mappings are as follows:" & @CRLF & "" & @CRLF & $RFile & @CRLF & "Please select an available drive letter, the application will map to server\myserver for you" & @CRLF & "" & @CRLF & "(Do not select M or N please)", "", "", "", 351) ;### Tidy Error: Level error -> EndIf is closing previous While EndIf If $mapto = "M" Or "N" Then $bad = MsgBox(0, "Invalid drive specification", "You have entered an invalid drive" & @CRLF & "Please try again") EndIf DriveMapAdd($mapto) ;### Tidy Error: Level error -> WEnd is closing previous If Wend SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
scriptkitty Posted November 16, 2004 Share Posted November 16, 2004 (edited) I make it a bit easier and remove some of the code:$file =$HFile = $RFile=If While 1 $mapto =EndIfIf $bad = EndIf DriveMapAdd($mapto) WEndsee the problem is from nesting.should look like:$file =$HFile =$RFile=While 1 If $mapto = EndIf If $bad = EndIf DriveMapAdd($mapto)WEndit could also look like this:$file =$HFile = $RFile=If While 1 $mapto = If $bad = EndIf DriveMapAdd($mapto) WEndEndIfI thought it might be easier if you removed all the clutter part of the code. Tidy is excelent for pointing out this type of thing. Edited November 16, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now