Page 1 of 1 1
Topic Options
#195446 - 2009-08-17 09:30 PM check file size and delete
sinsky Offline
Fresh Scripter

Registered: 2005-09-06
Posts: 7
Loc: washington dc
hi, how can i run a script at logon to check for a file and if the file is equal or greater than 5k delete it?
the file is located at c:\documents and settings\%username%\application data\microsoft\outlook\data.txt

i tried using a vbscript but i am having issues making this work -

we use kix for the logon script

thank you

Top
#195447 - 2009-08-17 11:01 PM Re: check file size and delete [Re: sinsky]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Please see in the manual:
Exist() - http://www.scriptlogic.com/Kixtart/htmlhelp/Functions/exist.htm
GetFileSize() - http://www.scriptlogic.com/Kixtart/htmlhelp/Functions/getfilesize.htm
Del - http://www.scriptlogic.com/Kixtart/htmlhelp/Commands/del.htm

pseudo code;
 Code:
$filename="path\file"
$maxsizeinK=5
if exist($filename)
  if getfilesize($filename)>$maxsizeinK*1024
    del $filename
  endif
endif 
_________________________
(... better days ahead)

Top
#195448 - 2009-08-17 11:54 PM Re: check file size and delete [Re: Allen]
sinsky Offline
Fresh Scripter

Registered: 2005-09-06
Posts: 7
Loc: washington dc
hi, thanks for the script -
i tried it but i get an unknown error -
cant seem to pause the script to get the complete error - but it seems as file path error. this is what i have as the file path
filename="C:\Documents and settings\%username%\Application Data\Microsoft\Outlook\data.txt"

thanks again

Top
#195449 - 2009-08-18 12:05 AM Re: check file size and delete [Re: sinsky]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Scripts, especially while debugging and testing, should be launched from a command prompt. If you do this, you will see all the messages and errors.

Also, Allen mentioned that this was "pseudo-code" - something that is thrown together without testing to give you the idea of what to do. It may not work, but will be darn close.

Take the script and add some debug messages to it, like "The file exists!" and such.. run it from the command prompt and see what you get. Give it a try and report back your results and we'll provide more guidance.

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

Top
#195450 - 2009-08-18 09:54 AM Re: check file size and delete [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Added some comments in Allen's code and inserted the path and filename to match your setup. The username can be used as a macro in kix. It has the @USERID macro that holds the current username. I also placed it outside quotes so it gets interpreted as it should.

I tried it on a test file and it works fine.

 Code:
Break on

;Set the filename and path of the file to be checked.
$filename = "C:\Documents and settings\" + @USERID + "\Application Data\Microsoft\Outlook\data.txt"

;Set the maximum size if the file (in bytes).
$maxsize = 5000

;Check if the file exists
If Exist($filename)
	;File exists so get the file size and see if it is bigger then the max file size.
	If GetFileSize($filename) > $maxsize
		;File is bigger then the max file size so delete it.
		Del $filename
	EndIf
EndIf 

;Sleep for 5 seconds so you can read the screen output if there is any.
Sleep 5
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195465 - 2009-08-19 08:19 PM Re: check file size and delete [Re: Mart]
sinsky Offline
Fresh Scripter

Registered: 2005-09-06
Posts: 7
Loc: washington dc
Thank you all for all the suggestions and the for providing the actual code. i tested it and it works just fine. i am new at using kix but i have been reading the documentations and it has a lot of excellent uses. I really appreciate your assistance on this.
Be back soon...

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
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.057 seconds in which 0.027 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