#205848 - 2012-09-28 10:49 AM
Read parmaters in from text file and loop through code
|
GeorgeLittle
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
|
|
|
|
#205850 - 2012-09-28 01:48 PM
Re: Read parmaters in from text file and loop through code
[Re: Glenn Barnas]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
$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
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
|
|
|
|
#205854 - 2012-09-28 03:16 PM
Re: Read parmaters in from text file and loop through code
[Re: Glenn Barnas]
|
GeorgeLittle
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
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Try
; 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!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 793 anonymous users online.
|
|
|