|
-
Oct 22nd, 2003, 09:49 PM
#1
Thread Starter
Lively Member
Does anyone know how to limit the size of a file? (Resolved)
I need to limit the size og my proggies log file based on some
sort of number i.e 2 meg or some such... i am going to use a
drop down of sizes to choose from...
does anyone have any ideas?
with respect
bindu
P.S
See Here for How to Setup Logging Easily
Download this Fantastic Tool
>>> mztools
That tool is utterly the best thing that has ever been invented for VB...
Last edited by binduau; Oct 22nd, 2003 at 11:03 PM.
-
Oct 22nd, 2003, 10:51 PM
#2
Fanatic Member
Well off the top of my head I'd say just run a check on the file when you go to write to it.
Example...
VB Code:
If FileLen(LogFile) > 2048 then
'Logfile = path of your logfile and 2048
'I think is approx 2 megs in bytes lol can't remember offhand.
'Do whatever you want to do with the file to keep it from getting bigger..
'One thing would be to skip the first line of the file and read in the rest and then save it
'plus the new line back into the file..
'Depends on how you save as to what line you would skip
End If
EDIT:
Assuming your using the same log file writing process as in that link you put in your message (didn't go to it till after I posted). It seems your newest error would be the last write done so you would have to skip the first one. The thing here also is though I see it actually takes up more than one line, so you'd have to skip multiple lines.
If you dont know how to read in and rewrite a file then post and I'll go into it tommorrow but about to go to bed so not going into it right now.
Last edited by StevenHickerson; Oct 22nd, 2003 at 10:58 PM.
-
Oct 22nd, 2003, 10:58 PM
#3
Actually, one megabyte would be 220 or 1,048,576 bytes meaning that two megabytes would be 2*220 or 2,097,152 bytes 
Edit: And for writing the file up to that maximum, you could append the file and then open it as binary while resaving only the last 2 MB's (or you could store it in RAM, append and trim as needed, and then save it so you never use more hard drive space than needed)
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 22nd, 2003, 10:59 PM
#4
Thread Starter
Lively Member
Yep i tollay forgot about FileLen Thanks a lot
Yeh That will do the job Thanks.. you will like this...
I am sure you will like this...
Originally posted by StevenHickerson
Well off the top of my head I'd say just run a check on the file when you go to write to it.
Example...
VB Code:
If FileLen(LogFile) > 2048 then
'Logfile = path of your logfile and 2048
'I think is approx 2 megs in bytes lol can't remember offhand.
'Do whatever you want to do with the file to keep it from getting bigger..
'One thing would be to skip the first line of the file and read in the rest and then save it
'plus the new line back into the file..
'Depends on how you save as to what line you would skip
End If
-
Oct 22nd, 2003, 11:10 PM
#5
Fanatic Member
Actually, one megabyte would be 220 or 1,048,576 bytes meaning that two megabytes would be 2*220 or 2,097,152 bytes
Oh yeah! It's 1024 Mb = 1 gig .. silly me =P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|