Limiting the size of a text file. 
Author Message
 Limiting the size of a text file.

I'm creating a log file in my application that is just text.  I want to
limit the file size of this file to keep disk space reasonable.  Is there a
function to truncate a file or limit it's size?

Paul Swanson



Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

Paul,

Quote:
>I'm creating a log file in my application that is just text.  I want to
>limit the file size of this file to keep disk space reasonable.  Is there a
>function to truncate a file or limit it's size?

I don't believe there is any global function that will limit the size a file
can grow.

You write a class or something that you call to write information to, and
have it check the file size to prevent it from getting too big.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com



Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

How would I truncate file size once I find out it's growing too large?



Quote:
> Paul,

> >I'm creating a log file in my application that is just text.  I want to
> >limit the file size of this file to keep disk space reasonable.  Is
there a
> >function to truncate a file or limit it's size?

> I don't believe there is any global function that will limit the size a
file
> can grow.

> You write a class or something that you call to write information to, and
> have it check the file size to prevent it from getting too big.

> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com



Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

Hi Paul,

--
Richard Grier
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications.
For information, look on my homepage at
http://ourworld.compuserve.com/homepages/richard_grier.
Use the Books link to order from Amazon.com.  For faster service, contact
the publisher at http://www.mabry.com.



Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

Hi Paul,

What I do is to write the last (X) entries to a temporary file (Open the
source file for Input, and the temporary file for Output).  Close the files,
and delete the original file.  Then use FileCopy to copy the temporary file
to the original filename.  Last, I delete the temporary file.

--
Richard Grier
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications.
For information, look on my homepage at
http://ourworld.compuserve.com/homepages/richard_grier.
Use the Books link to order from Amazon.com.  For faster service, contact
the publisher at http://www.mabry.com.



Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

Try this:

  LogFile = "C:\YOUR\PATH\YourFile.TXT"  'if the log file exists, kill it
  On Error Resume Next
  If FileLen(LogFile) > 20000 Then
    Kill LogFile
  End If



Quote:
> I'm creating a log file in my application that is just text.  I want to
> limit the file size of this file to keep disk space reasonable.  Is there
a
> function to truncate a file or limit it's size?

> Paul Swanson




Fri, 01 Sep 2000 03:00:00 GMT  
 Limiting the size of a text file.

Paul-
        Below is a quick routine to use after the
log has grown to the max size. This example
assumes you're adding new entries to the END
of the log. Obviously, this is not a finished routine,
merely a simplistic example.
                                        Joe

_________snip______________________________

Option Explicit
Private Const LOGRECORDSIZE& = 50
Private Const MAXSIZE& = 2000
Private Const LOGFILENAME$ = "c:\~Logfile.txt"

Private Sub Command1_Click()
    Dim iFreeFile As Integer
    Dim szTmp As String
    On Error GoTo err_MakeLog
    szTmp = String(MAXSIZE, 64)
    iFreeFile = FreeFile
    Open LOGFILENAME For Binary As #iFreeFile
    Put #iFreeFile, , szTmp
err_MakeLog:
    Close #iFreeFile
End Sub

Private Sub Command2_Click()
    Dim szDiscardRecord As String
    Dim szNewRecord As String
    Dim szRestOfFile As String
    Dim iFreeFile As Integer
    On Error GoTo err_AddEntry
    ' Initialize string lengths
    szNewRecord = String(LOGRECORDSIZE, 63)
    szDiscardRecord = Space(LOGRECORDSIZE)
    szRestOfFile = Space(MAXSIZE - LOGRECORDSIZE)
    iFreeFile = FreeFile
    Open LOGFILENAME For Binary As #iFreeFile
    Get #iFreeFile, , szDiscardRecord ' The first record
    Get #iFreeFile, , szRestOfFile
    Put #iFreeFile, 1, szRestOfFile ' Put W/O 1st rec
    Put #iFreeFile, , szNewRecord 'Add new rec
err_AddEntry:
    Close #iFreeFile
End Sub
Private Sub Form_Load()
    Command1.Caption = "Make a fake Log (2k)"
    Command2.Caption = "Add an Entry"
End Sub
___________snip____________________________
--
***********************************************************

Microsoft Developer MVP- Visual Basic
Check out Yankee Clipper Plus (April 1998
PCWorld magazine "Best Free Stuff Online")
www.tiac.net/users/lvasseur/ycphome.html
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)



Quote:
> I'm creating a log file in my application that is just text.  I want to
> limit the file size of this file to keep disk space reasonable.  Is there
a
> function to truncate a file or limit it's size?

> Paul Swanson




Sat, 02 Sep 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. getting beyond 32 k file size limit when editing into a text box

2. How to limit the size of the cell text for a DataGrid

3. How to limit the size of the cell text for a DataGrid

4. Output To File Size Limits

5. ini file size limit?

6. Word operating limits trouble and odd file size growth

7. HttpRequest Object file size limit or bug?

8. limit the file size for uploading

9. Access file size limit

10. Known user and file size limit 4 Access?

11. Input File Size Limit???

12. Size of Controls limited by Form Size ?

 

 
Powered by phpBB® Forum Software