Sign in to follow this  
Followers 0
Shadowpp

Looking for help on this script

2 posts in this topic

The intent of this this script is to read computer names from a file, map a drive to it and check:

1. If a directory exists

2. If a file exists

3. If the file is the correct size

4. Log results

Seems to work, but produces redundant results (see below). Any thoughts on how to eliminate the redundant results or advice on a better way to accomplish this would be greatly appreciated.

#NoTrayIcon

$SourceFile = FileOpen("c:\TDLUPGRADE_Full.txt", 0)

If FileExists("c:\script\status.txt") Then FileDelete ("c:\script\status.txt")

If $SourceFile  = -1 Then
    MsgBox(0, "Error", "Cannot find Source file.")
    Exit
EndIf

While 1
    $line = FileReadLine($SourceFile)
    $ResultFile = FileOpen("c:\script\status.txt", 9)
    If @error = -1 Then ExitLoop
    DriveMapAdd("J:", "\\" & $line & ".myplace.com\cdrive")
    If FileExists("J:\Apps") Then
        If FileExists ("J:\Apps\TDLUpgrade") Then
            If FileExists ("J:\Apps\TDLUpgrade\TDLUpgrade.exe") Then
                $size = FileGetSize("J:\Apps\TDLUpgrade\TDLUpgrade.exe")
                If $size = 17681956 Then
                    FileWrite($ResultFile, $line & " - Successfully Deployed" & @CRLF)
                Else
                    FileWrite($ResultFile, $line & " - File Too Small" & @CRLF)
                EndIf
            Else
                FileWrite($ResultFile, $line & " - File Not Deployed" & @CRLF)
            EndIf
        Else
            FileWrite($ResultFile, $line & " - Directory Not Created" & @CRLF)
        EndIf
    Else
        FileWrite($ResultFile, $line & " - No Connection" & @CRLF)
    EndIf
    DriveMapDel("J:")
    SplashTextOn ("Please Wait...", "Completed " & $line & " check!", 290, 50, -1, -1, 22, "", 16)
    FileClose($ResultFile)
WEnd

DriveMapDel("J:")
FileClose($SourceFile)
FileClose($ResultFile)
SplashOff()
MsgBox (0, "Complete!", "The script has finished.")

Source File:

STR00001
STR00025
STR00030
STR00035
STR00073
STR00075
STR00129
STR00159
STR00210
STR00224
STR00266
STR00275
STR00279
STR00288
STR00303
STR00352
STR00408
STR00426
STR00446
STR00467
STR00488
STR00540

Output File:

STR00001 - File Too Small
STR00025 - File Too Small
STR00030 - Successfully Deployed
STR00035 - File Too Small
STR00073 - Successfully Deployed
STR00075 - Successfully Deployed
STR00001 - Successfully Deployed
STR00025 - File Too Small
STR00030 - Successfully Deployed
STR00035 - File Too Small
STR00073 - Successfully Deployed
STR00075 - Successfully Deployed
STR00129 - No Connection
STR00129 - No Connection
STR00159 - File Too Small
STR00159 - Successfully Deployed
STR00210 - Successfully Deployed
STR00210 - Successfully Deployed
STR00224 - File Too Small
STR00224 - File Too Small
STR00266 - File Too Small
STR00266 - File Too Small
STR00275 - File Too Small
STR00275 - File Too Small
STR00279 - File Too Small
STR00279 - Successfully Deployed
STR00288 - Successfully Deployed
STR00288 - Successfully Deployed
STR00303 - No Connection
STR00303 - No Connection
STR00352 - Successfully Deployed
STR00352 - Successfully Deployed
STR00408 - File Too Small
STR00408 - File Too Small
STR00426 - File Too Small
STR00426 - File Too Small
STR00446 - No Connection
STR00446 - No Connection
STR00467 - Successfully Deployed
STR00467 - Successfully Deployed
STR00488 - Successfully Deployed
STR00488 - File Too Small
STR00540 - File Too Small
STR00540 - Successfully Deployed

Share this post


Link to post
Share on other sites



only obvious thing I see wrong the the @error test . should follow the FileReadLine() because you need to test for EOF.

Here is a version with some more changes:

#NoTrayIcon

$SourceFile = FileOpen("c:\TDLUPGRADE_Full.txt", 0)

If $SourceFile = -1 Then
    MsgBox(0, "Error", "Cannot find Source file.")
    Exit
EndIf

If FileExists("c:\script\status.txt") Then FileDelete("c:\script\status.txt")
$ResultFile = FileOpen("c:\script\status.txt", 9)

While 1
    $line = FileReadLine($SourceFile)
    If @error = -1 Then ExitLoop
    DriveMapAdd("J:", "\\" & $line & ".myplace.com\cdrive")
    If FileExists("J:\Apps") Then
        If FileExists("J:\Apps\TDLUpgrade") Then
            If FileExists("J:\Apps\TDLUpgrade\TDLUpgrade.exe") Then
                $size = FileGetSize("J:\Apps\TDLUpgrade\TDLUpgrade.exe")
                If $size = 17681956 Then
                    FileWrite($ResultFile, $line & " - Successfully Deployed" & @CRLF)
                Else
                    FileWrite($ResultFile, $line & " - File Too Small" & @CRLF)
                EndIf
            Else
                FileWrite($ResultFile, $line & " - File Not Deployed" & @CRLF)
            EndIf
        Else
            FileWrite($ResultFile, $line & " - Directory Not Created" & @CRLF)
        EndIf
    Else
        FileWrite($ResultFile, $line & " - No Connection" & @CRLF)
    EndIf
    DriveMapDel("J:")
    SplashTextOn("Please Wait...", "Completed " & $line & " check!", 290, 50, -1, -1, 22, "", 16)
WEnd

DriveMapDel("J:")
FileClose($SourceFile)
FileClose($ResultFile)
SplashOff()
MsgBox(0, "Complete!", "The script has finished.")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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