Page 1 of 1 1
Topic Options
#168146 - 2006-09-20 11:53 PM filesize comparison no working?
Lucid Offline
Fresh Scripter

Registered: 2006-09-20
Posts: 11
Hello All,

I'm working on my very first kix script and running into trouble. Essentially we have an update to a program we use in the office that simply requires an MDE file to be replaced on the user's workstation. Since the environment is not managed very well I'm trying to put in some checks to make sure the file that needs to be replaced is actually there. Since this script will run at login for a few days as users come in and out of the environment I want to make sure it doesn't keep replacing the file for users that have already had it replaced. My newb way to do this was to do a filesize comparison and then if its different to replace the file. I also wanted to create a log file of what's going on. So after all that, here is the script I came up with (specific paths and company info snipped):

$wrkFile="[snip]balaboss.mde"
$ServFile="[snip]balaboss.mde"
$Logfile = "c:\" + @month + @mdayno + ".log"

If Exist ($wrkFile)
$wrksize=getfilesize($wrkfile)
$servsize=getfilesize($servfile)
IF $wrksize<>$serversize
copy $servfile "[snip]balaboss.mde"
$operation = "file replaced"
else
$operation = "file left alone"
endif
else
$operation = "file not found"
endif
If Open (1,$logfile,5) = 0
Writeline (1, @wksta + " / " + @userid + @CRLF + "Workstation File Size = " + $wrksize + " " + "Server File Size = " + $servsize + @CRLF + "Result = " + $operation + @CRLF + @CRLF+ @CRLF)
Close(1)
Endif

The trouble that I am running into is that it appears to still be copying the file over even when its the same size (at least that's what my $operation variable is showing). Here's an part of the output log for 3 attempts (first with the file missing from the workstation, second with the old file where it should be, and third after the file has been updated):

workstation / username
Workstation File Size = Server File Size =
Result = file not found


workstation / username
Workstation File Size = 46123008 Server File Size = 46630912
Result = file replaced


workstation / username
Workstation File Size = 46630912 Server File Size = 46630912
Result = file replaced


Can anyone point me to where I'm going wrong. I'm also open to revamping the whole thing if anyone has a better suggestion on how to code it so the it checks if the file exists and is different from the new one (file size was the first thing I could come up with).

Many thanks in advance.

Top
#168147 - 2006-09-21 12:15 AM Re: filesize comparison no working?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Code:

$servsize=getfilesize($servfile)
IF $wrksize<>$serversize


I would like to recommend you a header in your scripts like
Code:

If NOT @LOGONMODE
Break On
EndIf
Dim $RC
$RC = SetOption("Explicit","On") ; <-- This will help you
$RC = SetOption("NoVarsInStrings","On")
$RC = SetOption("NoMacrosInStrings","On")
$RC = SetOption("WrapAtEOL","On")


Top
#168148 - 2006-09-21 02:45 AM Re: filesize comparison no working?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Curious - if this affects file redirection as well or just console.

$RC = SetOption("WrapAtEOL","On")


Too lazy to test, but I don't normally use that one myself. Suppose though if it does not affect log files then no reason I shouldn't use it.

Top
#168149 - 2006-09-21 09:20 AM Re: filesize comparison no working?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Do you mean
Code:

$RC = RedirectOutput(@SCRIPTDIR + "\RedirectOutput.txt",1)


It does not affect RedirectOutput because a text file is not limited to 80 columns like an ancient screen in DOS. Lines are just typed to the end.
I use it for output on screen, to avoid overtyping on the same line.

Top
#168150 - 2006-09-21 06:00 PM Re: filesize comparison no working?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the ancient limit has nothing to do with this.
but the limit of the target does.
so, if you have 120 char wide console window, it wraps there.
and like witto said, text files don't have such width limitations.

Top
#168151 - 2006-09-21 06:15 PM Re: filesize comparison no working?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You're right, but well, you know what I mean. If I open a Command Prompt, most of the time the window is 80 chars wide x 25 chars high.
Top
#168152 - 2006-09-21 08:20 PM Re: filesize comparison no working?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Not for me, got tired of that so now the logon script changes it for me during logon to any machine I log onto.
Top
#168153 - 2006-09-21 08:21 PM Re: filesize comparison no working?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
oh... and guess I should RTM more often.
It is right there in the manual.

Quote:

Enables/disables wrapping of console output at the end of a line




Otay, have added it to my header for scripts.

Top
#168154 - 2006-09-21 10:23 PM Re: filesize comparison no working?
Lucid Offline
Fresh Scripter

Registered: 2006-09-20
Posts: 11
Stupid newb mistake. I will fix the error and test it out and get back to you. Can you explain what this "header" that you recommend does, or point me to a place that will explain it.

Thanks for your help.

Top
#168155 - 2006-09-21 10:26 PM Re: filesize comparison no working?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
SetOption("Explicit","On")
Would force you to define ALL your vars and would catch typos like yours. It is explained in the manual.

Top
#168156 - 2006-09-22 12:27 AM Re: filesize comparison no working?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Read the Kix2010.doc. It is not that big and it contains all the answers.
Code:

If NOT @LOGONMODE
Break On
EndIf


If you break a KiX script, per default KiXtart will log off your computer. This is OK for login scripts. But for other purposes, most of the time this behaviour is unwanted. Take a look at the vivid discussion: Break On should be the deafult.
Code:

Dim $RC
$RC = SetOption("Explicit","On")


If you do not Dim a variable, it is global. I prefer local variables to avoid confusion. The Explicit option forces to declare variables.
Code:

$RC = SetOption("NoVarsInStrings","On")


If a $-sign is used between quotes, KiX tries to translate it together with the trailing chars to a variable. You would have to double the $ ($$) to show it is not a var. Only exception is when the $ is at the last place of a string, e.g. "\\Server\HiddenShare$" or "This is a $ symbol". Setting the NoVarsInStrings option makes that a $ between quotes is always a part of a string.
Code:

$RC = SetOption("NoMacrosInStrings","On")
Code:

If @ is used between quotes, KiX tries to translate it,together with the trailing chars, to a macro. you would have to double the @ (@@) to avoid it.
Setting the NoMacrosInStrings option on does just what is says: No Macros In Strings.
Code:

$RC = SetOption("WrapAtEOL","On")


If screen output is wider then the character width of a command window, the same line is overwritten. The WrapAtEOL option adds a crlf to the character at the end of the line.
Top
#168157 - 2006-09-22 04:23 AM Re: filesize comparison no working?
Lucid Offline
Fresh Scripter

Registered: 2006-09-20
Posts: 11
Thank you kindly for finding the flaw in my script and for explaining the header options to help improve my future endevors. I have fixed the script and it works great.

Just one last question, I seem to get a line with "00" in the command prompt window after my script completes before I get a prompt back. It doesn't seem to keep the script from running properly, but I'm wondering if it indicates a problem I should be concerned with.

Top
#168158 - 2006-09-22 05:17 AM Re: filesize comparison no working?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There is a FAQ on that.
Top
#168159 - 2006-09-22 05:34 AM Re: filesize comparison no working?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Please take a look here:


Suppressing Results when running scripts
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81593

Top
#168160 - 2006-09-22 07:06 AM Re: filesize comparison no working?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I hope that answered your question and you got rid of these zeroes?
The $RC in my header does the same.

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 895 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.067 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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