Page 1 of 1 1
Topic Options
#205848 - 2012-09-28 10:49 AM Read parmaters in from text file and loop through code
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
Here is a script I used to validate some files. What I would like to do is alter this script to loop through a series of files in the $File1 variable read in from a text file any pointers ?

Thanks

;Declare The File Paths
$File1 = "Hippo.txt";Check it exists
If Exist ($File1) = 0
MessageBox ("Error1:Consultant ID File Does Not Exist."+ Chr(13)+
"Please contact IT Support on , as you will not be able to log in,"+Chr(13)+
"You will now be logged off this system!.",
"WARNING MESSAGE", 48, 300)
Else
;Check if the file is of a size greater than 0KB
$UIDSIZE = GetFileSize($UIDINFO)
If $UIDSIZE = 0
MessageBox ("Error2:Consultant ID File Is To Small."+ Chr(13)+
"Please contact IT Support on 1234, as you will not be able to log in,"+Chr(13)+
"You will now be logged off this system!.",
"WARNING MESSAGE", 48, 300)
LogOff (1)
Sleep 10

EndIf


Edited by GeorgeLittle (2012-09-28 11:51 AM)

Top
#205849 - 2012-09-28 01:13 PM Re: Read parmaters in from text file and loop through code [Re: GeorgeLittle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
My FileIO UDF can load a text file into an array that you can enumerate.
 Code:
$aFiles = FileIO($ListFile, 'R')
For each $File in $aFiles
 ; your stuff
Next
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#205850 - 2012-09-28 01:48 PM Re: Read parmaters in from text file and loop through code [Re: Glenn Barnas]
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
 Code:
$ListFile ="C:\List.txt"
$aFiles = FileIO($ListFile, 'R')
For each $File in $aFiles
;Declare The File Paths
$File1 = $File 
If Exist ($File1) = 0
 MessageBox ("Error1:Consultant ID File Does Not Exist."+ Chr(13)+
 "Please contact IT Support on , as you will not be able to log in,"+Chr(13)+
 "You will now be logged off this system!.",
 "WARNING MESSAGE", 48, 300)
Else
 ;Check if the file is of a size greater than 0KB
 $UIDSIZE = GetFileSize($UIDINFO)
 If $UIDSIZE = 0
 MessageBox ("Error2:Consultant ID File Is To Small."+ Chr(13)+
 "Please contact IT Support on 1234, as you will not be able to log in,"+Chr(13)+
 "You will now be logged off this system!.",
 "WARNING MESSAGE", 48, 300)
 LogOff (1)
 Sleep 10

 EndIf 
Next
Like that ?


Edited by Glenn Barnas (2012-09-28 02:53 PM)
Edit Reason: Please use code tags!

Top
#205851 - 2012-09-28 02:42 PM Re: Read parmaters in from text file and loop through code [Re: GeorgeLittle]
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
So here is the script I have tried and it works a treat other than I get the message warning me a file does not exist even when it correctly identfies the one file in the list thats working hmmmm



$ListFile = "C:\scripts\list.txt"

$aFiles = FileIO($ListFile, 'R')
For each $File in $aFiles

If Exist ($File) = 0
MessageBox ("Error1:Consultant ID File Does Not Exist."+ Chr(13)+
"Please contact IT Support on , as you will not be able to log in,"+Chr(13)+
"You will now be logged off this system!.",
"WARNING MESSAGE", 48, 300)
? "File Is Missing" + $File


Edited by GeorgeLittle (2012-09-28 02:56 PM)

Top
#205852 - 2012-09-28 02:55 PM Re: Read parmaters in from text file and loop through code [Re: GeorgeLittle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Did you download and include the FileIO UDF?

The latest version is here.

Also - no need to assign $File to $File1 - either replace all $File1 with $File or vice-versa and eliminate the $File1=$File line.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#205854 - 2012-09-28 03:16 PM Re: Read parmaters in from text file and loop through code [Re: Glenn Barnas]
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
I have downloaded and included the FileIO UDF and tidied up the other $File to $File1 it is working but allways seems to falsley report a file as not existing
Top
#205855 - 2012-09-28 03:26 PM Re: Read parmaters in from text file and loop through code [Re: GeorgeLittle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Try
 Code:
; where files to check are defined
$ListFile ="C:\List.txt"

; load list into array
$aFiles = FileIO($ListFile, 'R')

; enumerate array
For each $File in $aFiles
 ; Check if file exists and is not empty
 If Exist($File)		; exists, verify non-zero size
   If GetFileSize($File) = 0	; Empty - complain!
    MessageBox ("Error2:Consultant ID File Is To Small."+ Chr(13)+
    "Please contact IT Support on 1234, as you will not be able to log in,"+Chr(13)+
    "You will now be logged off this system!.",
    "WARNING MESSAGE", 48, 300)
    LogOff(1)
  EndIf
 Else				; does not exist
  MessageBox ("Error1:Consultant ID File Does Not Exist."+ Chr(13)+
  "Please contact IT Support on , as you will not be able to log in,"+Chr(13)+
  "You will now be logged off this system!.",
  "WARNING MESSAGE", 48, 300)
  LogOff(1)
 EndIf
Next
Your GetFileSize did not reference the file..

Glenn


Edited by Glenn Barnas (2012-09-28 03:28 PM)
Edit Reason: missing comment tag
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 793 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.059 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org