Sign in to follow this  
Followers 0
jon_in_vermont

Newbie needs fresh eyes to fix loop

6 posts in this topic

This little script (see below) gets hung up in an infinite loop. I know it's ugly, but seems to work (except for the loop!). I need some caffine, but I would appreciate a review/correction from a set of fresh eyes.

Thanks in advance,

Jon

cs ----------------------------------------------------------------------------

AutoIt Version: 3.1.1.0

Author: jc

Name: addstudentlist.au3

Date: August 16 2006

Script Function: add student home directories and sub folders for Geo105

Template AutoIt script.

#ce ----------------------------------------------------------------------------

$message = "Select Text File containing student e-mail names"

$file = FileOpenDialog($message, "\\geo\2006-07\", "File (*.txt)", 1 + 4, "geo105listb.txt" )

;sample excerpt from text file (geo105listb.txt

;abelewc2@email.somewhere.edu

;hbierr1@email.somewhere.edu

;hbier3@email.somewhere.edu

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

$parse = StringInStr($line, "@") ; find @ in e-mail address

$realnum = $parse - 1 ; subtract 1 from count ($parse) to get correct number of characters

$username = StringLeft($line, $realnum) ; extract string (username only)

If FileExists("\\geo\DATAVOL\geohome\"& $username) Then

MsgBox(4096, "Warning", "User: " & $username & " home directory already exists.")

Else

DirCreate("\\geo\DATAVOL\geohome\"& $username)

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Temp")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Earthquakes")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Slopes")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Floods")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Hurricanes")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Impacts")

DirCreate("\\geo\DATAVOL\geohome\"& $username &"\Volcanoes")

MsgBox(0,"Home Directory and sub folders added for:",$username) ; test msgbox

EndIf

Wend

FileClose($file)

Share this post


Link to post
Share on other sites



Hi,

changed a few things, but nothing important. :P

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.1.1.0
    Author: jc
    Name: addstudentlist.au3
    Date: August 16 2006
    
    Script Function: add student home directories and sub folders for Geo105
    Template AutoIt script.
    
#ce ----------------------------------------------------------------------------

$message = "Select Text File containing student e-mail names"
$file = FileOpenDialog($message, "\\geo\2006-07\", "File (*.txt)", 1 + 2, "geo105listb.txt")
;sample excerpt from text file (geo105listb.txt
;abelewc2@email.somewhere.edu

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $username = StringLeft($line, StringInStr($line, "@")-1) ; extract string (username only)
    If FileExists("\\geo\DATAVOL\geohome\" & $username) Then
        MsgBox(4096, "Warning", "User: " & $username & " home directory already exists.")
    Else
        DirCreate("\\geo\DATAVOL\geohome\" & $username)
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Temp")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Earthquakes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Slopes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Floods")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Hurricanes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Impacts")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Volcanoes")
        MsgBox(0, "Home Directory and sub folders added for:", $username) ; test msgbox
    EndIf
WEnd
FileClose($file)
Exit(0)

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

Share this post


Link to post
Share on other sites

Hi,

changed a few things, but nothing important. :P

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.1.1.0
    Author: jc
    Name: addstudentlist.au3
    Date: August 16 2006
    
    Script Function: add student home directories and sub folders for Geo105
    Template AutoIt script.
    
#ce ----------------------------------------------------------------------------

$message = "Select Text File containing student e-mail names"
$file = FileOpenDialog($message, "\\geo\2006-07\", "File (*.txt)", 1 + 2, "geo105listb.txt")
;sample excerpt from text file (geo105listb.txt
;abelewc2@email.somewhere.edu

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $username = StringLeft($line, StringInStr($line, "@")-1) ; extract string (username only)
    If FileExists("\\geo\DATAVOL\geohome\" & $username) Then
        MsgBox(4096, "Warning", "User: " & $username & " home directory already exists.")
    Else
        DirCreate("\\geo\DATAVOL\geohome\" & $username)
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Temp")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Earthquakes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Slopes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Floods")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Hurricanes")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Impacts")
        DirCreate("\\geo\DATAVOL\geohome\" & $username & "\Volcanoes")
        MsgBox(0, "Home Directory and sub folders added for:", $username) ; test msgbox
    EndIf
WEnd
FileClose($file)
Exit(0)

So long,

Mega

Share this post


Link to post
Share on other sites

Thanks Mega,

Certainly cleaner code, but still stuck in the loop (unless I'm really missing something!)

Jon

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Mega,

Certainly cleaner code, but still stuck in the loop (unless I'm really missing something!)

Jon

FileOpenDialog() is actually mis-named. It doesn't open the file, it just returns a string of the path. Take the path given and use it to open the file, saving the handle. Then use that handle for your FileReadLine():

$file = FileOpenDialog($message, "\\geo\2006-07\", "File (*.txt)", 1 + 2, "geo105listb.txt")
$hFile = FileOpen($file)oÝ÷ Ù«­¢+Ù]¡¥±Ä(ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¡¥±¤

Hope that helps!

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks PsaltyDS - That did the trick.

just added the "read" mode to ..... $hFile = FileOpen($file,0)

Many thanks to you and Mega

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