Board index » delphi » Can you obtain the size of a file witout using reset?

Can you obtain the size of a file witout using reset?

Is there anyway to obtain the filesize of a file without opening it? I read
the docs on the filesize procedure and Reset procedure...Reset said, if the
file is first open, it will then close it and reopen it. Filesize wants the
file open. I want to watch the size of a database (Progress database). When
my app needs to run, the database will already be open. I do not want to
mess with the database in anyway, just want the size of it. Do I have any
options?

Chuck Condron

Regional IT Manager

Clear Channel Information Technologies

ChuckCond...@ClearChannel.com

AIM Screen Name: Vulcan39

 

Re:Can you obtain the size of a file witout using reset?


Quote
"Chuck Condron" <chuckcond...@clearchannel.com> wrote in message

news:pov%6.7496$ck5.750074@newsread2.prod.itd.earthlink.net...

Quote
> Is there anyway to obtain the filesize of a file without opening it? I
read
> the docs on the filesize procedure and Reset procedure...Reset said, if
the
> file is first open, it will then close it and reopen it. Filesize wants
the
> file open. I want to watch the size of a database (Progress database).
When
> my app needs to run, the database will already be open. I do not want to
> mess with the database in anyway, just want the size of it. Do I have any
> options?

Presuming that you are not using the same file variable to open the file (in
which case there is no need for the Reset) a Reset will have no effect on
the rest of your program, so using FileSize should be ok (presuming you can
open the file). The information returned by FindFirst includes the file
size. There is also the GetCompressedFileSize function documented in the Win
SDK help.

I'm not sure how accurate file size information is going to be on a file
that is open and being added to by some other handle.

Re:Can you obtain the size of a file witout using reset?


Unless the Database is well written there is a possibility that its
reported size from the directory entry will not be its true size.

Here is my FileLen routine :-

{ ##########################################

Quote
}

Function FileLen( Fle:String ):Integer;
var
  L9 : Integer;
  Handle: THandle;
  FindData: TWin32FindData;
begin
  Result := -1;
  { Check for '*' and '?' }
  For L9 := 1 To Length( Fle ) Do
      If ( Fle[L9] = '*' ) Or ( Fle[L9] = '?' ) Then
         Exit;

  Handle := FindFirstFile(PChar(Fle), FindData);
  if Handle <> INVALID_HANDLE_VALUE then
  begin
    Windows.FindClose(Handle);
    if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0
then
    begin
      Result := FindData.nFileSizeLow ;  // Note - Up to 2 Gb
      Exit;
    end;
  end;

End;

On Sun, 01 Jul 2001 01:53:25 GMT, "Chuck Condron"

Quote
<chuckcond...@clearchannel.com> wrote:
>Is there anyway to obtain the filesize of a file without opening it? I read
>the docs on the filesize procedure and Reset procedure...Reset said, if the
>file is first open, it will then close it and reopen it. Filesize wants the
>file open. I want to watch the size of a database (Progress database). When
>my app needs to run, the database will already be open. I do not want to
>mess with the database in anyway, just want the size of it. Do I have any
>options?

>Chuck Condron

>Regional IT Manager

>Clear Channel Information Technologies

>ChuckCond...@ClearChannel.com

>AIM Screen Name: Vulcan39

Re:Can you obtain the size of a file witout using reset?


Quote
Chuck Condron wrote:
> Is there anyway to obtain the filesize of a file without opening it?

Yes, use FindFirst/FindClose and pull it out of the tsearchrec.  Don't open a
file just to get the filesize because: (a) it might be in use by another
program and (b) that updates the last accessed time stamp of the file.

--
Kent Briggs, kbri...@briggsoft.com
Briggs Softworks, http://www.briggsoft.com

Re:Can you obtain the size of a file witout using reset?


The size of a file may be found by querying the directory .. HOWEVER ..
the size stored there is usually the last size the file had when it was
last closed.  If a file has been recently created, its size is zero.  If
the file is currently open and has been extended, the directory-reported
size will not yet change.

Extremely large files can also present a problem.

The FindFirst(), FindClose(), et-al Delphi functions can be used to
obtain the directory-reported size of a file.

Quote
>Chuck Condron wrote:

> Is there anyway to obtain the filesize of a file without opening it? I read
> the docs on the filesize procedure and Reset procedure...Reset said, if the
> file is first open, it will then close it and reopen it. Filesize wants the
> file open. I want to watch the size of a database (Progress database). When
> my app needs to run, the database will already be open. I do not want to
> mess with the database in anyway, just want the size of it. Do I have any
> options?

------------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)
Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  "Click click, it's fixed!" {tm}
> http://www.sundialservices.com/products/chimneysweep

Re:Can you obtain the size of a file witout using reset?


Quote
Sundial Services wrote:
> Extremely large files can also present a problem.

Not if you get the size from SearchRec.FindData:

size64:=SearchRec.FindData.nFileSizeHigh;
size64:=(size64 shl 32) or SearchRec.FindData.nFileSizeLow;

--
Kent Briggs, kbri...@briggsoft.com
Briggs Softworks, http://www.briggsoft.com

Re:Can you obtain the size of a file witout using reset?


Yes - but to give Sundial fair credit his other point was valid -
lousily written databases will not update the directory even though
the file has been extended.

On Mon, 02 Jul 2001 12:02:34 -0500, Kent Briggs

Quote
<kbri...@briggsoft.com> wrote:
>Sundial Services wrote:

>> Extremely large files can also present a problem.

>Not if you get the size from SearchRec.FindData:

>size64:=SearchRec.FindData.nFileSizeHigh;
>size64:=(size64 shl 32) or SearchRec.FindData.nFileSizeLow;

>--
>Kent Briggs, kbri...@briggsoft.com
>Briggs Softworks, http://www.briggsoft.com

Re:Can you obtain the size of a file witout using reset?


Hey gang..thanks for the help!  I actually had solved it on my own before I
read all of your replys but here is what I came up with:

procedure TForm1.Timer1Timer(Sender: TObject);

begin

findfirst('R:\Database\Prophet.Db',faAnyfile, sr);

if sr.Size > (MaxSize.AsInteger*1000000) then begin

Beep;

Case DayOfWeek(now) of

1: if Sun.Checked then btnSendMail.Click;

2: if Mon.Checked then btnSendMail.Click;

3: if Tue.Checked then btnSendMail.Click;

4: if Wed.Checked then btnSendMail.Click;

5: if Thu.Checked then btnSendMail.Click;

6: if Fri.Checked then btnSendMail.Click;

7: if Sat.Checked then btnSendMail.Click;

end;

end;//end if

findclose(sr);

end;

(sr is declared globally)..

Quote
"Chuck Condron" <chuckcond...@clearchannel.com> wrote in message

news:pov%6.7496$ck5.750074@newsread2.prod.itd.earthlink.net...
Quote
> Is there anyway to obtain the filesize of a file without opening it? I
read
> the docs on the filesize procedure and Reset procedure...Reset said, if
the
> file is first open, it will then close it and reopen it. Filesize wants
the
> file open. I want to watch the size of a database (Progress database).
When
> my app needs to run, the database will already be open. I do not want to
> mess with the database in anyway, just want the size of it. Do I have any
> options?

> Chuck Condron

> Regional IT Manager

> Clear Channel Information Technologies

> ChuckCond...@ClearChannel.com

> AIM Screen Name: Vulcan39

Re:Can you obtain the size of a file witout using reset?


If I were you I would do the FindClose immediately after the FindFirst
- also I would box it into a function - also how are you handling an
error from FindFirst - have a look at how Delphi does it.

On Tue, 03 Jul 2001 16:09:27 GMT, "Chuck Condron"

Quote
<chuckcond...@clearchannel.com> wrote:
>Hey gang..thanks for the help!  I actually had solved it on my own before I
>read all of your replys but here is what I came up with:

>procedure TForm1.Timer1Timer(Sender: TObject);

>begin

>findfirst('R:\Database\Prophet.Db',faAnyfile, sr);

>if sr.Size > (MaxSize.AsInteger*1000000) then begin

>Beep;

>Case DayOfWeek(now) of

>1: if Sun.Checked then btnSendMail.Click;

>2: if Mon.Checked then btnSendMail.Click;

>3: if Tue.Checked then btnSendMail.Click;

>4: if Wed.Checked then btnSendMail.Click;

>5: if Thu.Checked then btnSendMail.Click;

>6: if Fri.Checked then btnSendMail.Click;

>7: if Sat.Checked then btnSendMail.Click;

>end;

>end;//end if

>findclose(sr);

>end;

>(sr is declared globally)..

>"Chuck Condron" <chuckcond...@clearchannel.com> wrote in message
>news:pov%6.7496$ck5.750074@newsread2.prod.itd.earthlink.net...
>> Is there anyway to obtain the filesize of a file without opening it? I
>read
>> the docs on the filesize procedure and Reset procedure...Reset said, if
>the
>> file is first open, it will then close it and reopen it. Filesize wants
>the
>> file open. I want to watch the size of a database (Progress database).
>When
>> my app needs to run, the database will already be open. I do not want to
>> mess with the database in anyway, just want the size of it. Do I have any
>> options?

>> Chuck Condron

>> Regional IT Manager

>> Clear Channel Information Technologies

>> ChuckCond...@ClearChannel.com

>> AIM Screen Name: Vulcan39

Re:Can you obtain the size of a file witout using reset?


I have not written any error handling code at this time.  To look at how
Delphi does it, check the example for the findfirst?

I didnt think I could run findclose until I was done with using it.  What
happens if it is left open until the other items are finished?

By puting it into a function, how does that help things?  This timer event
is the only place its used.

I am only asking to learn.  I am in NO way a professional programmer, I only
play one on the weekends hehehe...I just code a few things for our
corporation from time to time to solve a few things we need.

I appreciate the advise!!!

Quote
"J French" <je...@iss.u-net.com> wrote in message

news:3b41f99c.2897262@news.u-net.com...
Quote
> If I were you I would do the FindClose immediately after the FindFirst
> - also I would box it into a function - also how are you handling an
> error from FindFirst - have a look at how Delphi does it.

> On Tue, 03 Jul 2001 16:09:27 GMT, "Chuck Condron"
> <chuckcond...@clearchannel.com> wrote:

> >Hey gang..thanks for the help!  I actually had solved it on my own before
I
> >read all of your replys but here is what I came up with:

> >procedure TForm1.Timer1Timer(Sender: TObject);

> >begin

> >findfirst('R:\Database\Prophet.Db',faAnyfile, sr);

> >if sr.Size > (MaxSize.AsInteger*1000000) then begin

> >Beep;

> >Case DayOfWeek(now) of

> >1: if Sun.Checked then btnSendMail.Click;

> >2: if Mon.Checked then btnSendMail.Click;

> >3: if Tue.Checked then btnSendMail.Click;

> >4: if Wed.Checked then btnSendMail.Click;

> >5: if Thu.Checked then btnSendMail.Click;

> >6: if Fri.Checked then btnSendMail.Click;

> >7: if Sat.Checked then btnSendMail.Click;

> >end;

> >end;//end if

> >findclose(sr);

> >end;

> >(sr is declared globally)..

> >"Chuck Condron" <chuckcond...@clearchannel.com> wrote in message
> >news:pov%6.7496$ck5.750074@newsread2.prod.itd.earthlink.net...
> >> Is there anyway to obtain the filesize of a file without opening it? I
> >read
> >> the docs on the filesize procedure and Reset procedure...Reset said, if
> >the
> >> file is first open, it will then close it and reopen it. Filesize wants
> >the
> >> file open. I want to watch the size of a database (Progress database).
> >When
> >> my app needs to run, the database will already be open. I do not want
to
> >> mess with the database in anyway, just want the size of it. Do I have
any
> >> options?

> >> Chuck Condron

> >> Regional IT Manager

> >> Clear Channel Information Technologies

> >> ChuckCond...@ClearChannel.com

> >> AIM Screen Name: Vulcan39

Re:Can you obtain the size of a file witout using reset?


so far, with the code I posted in a post after yours, it seems to be working
fine.  This routine runs once per hour and I see it reporting different
sizes, so the database must be updating the size.  It is about 990 megs.
This will be looking at a file size up to 2 gig.

The reason we need this app is to monitor the size of this database (a
Progress Database) that is part of some automation software that Radio
Stations use.  Most stations that use automation, do not have any humans
around or brain dead DJs hehehe.  Anyway, we have found that when this
database gets to be 1.5 gigs...it will crash and sometimes it trashes itself
in the process.  The company that makes the automation software has some
reindexing utils that can be run to reduce the size of the database, but we
want to warn an engineer or IT dude BEFORE it gets tooooo big...

Quote
"Sundial Services" <info_...@sundialservices.com> wrote in message

news:3B408834.7AC@sundialservices.com...
Quote
> The size of a file may be found by querying the directory .. HOWEVER ..
> the size stored there is usually the last size the file had when it was
> last closed.  If a file has been recently created, its size is zero.  If
> the file is currently open and has been extended, the directory-reported
> size will not yet change.

> Extremely large files can also present a problem.

> The FindFirst(), FindClose(), et-al Delphi functions can be used to
> obtain the directory-reported size of a file.

> >Chuck Condron wrote:

> > Is there anyway to obtain the filesize of a file without opening it? I
read
> > the docs on the filesize procedure and Reset procedure...Reset said, if
the
> > file is first open, it will then close it and reopen it. Filesize wants
the
> > file open. I want to watch the size of a database (Progress database).
When
> > my app needs to run, the database will already be open. I do not want to
> > mess with the database in anyway, just want the size of it. Do I have
any
> > options?
> ------------------------------------------------------------------
> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
> mailto:i...@sundialservices.com  (PGP public key available.)
> > Fast(!), automatic table-repair with two clicks of the mouse!
> > ChimneySweep(R):  "Click click, it's fixed!" {tm}
> > http://www.sundialservices.com/products/chimneysweep

Re:Can you obtain the size of a file witout using reset?


Quote
"Chuck Condron" <cccondronspr...@earthlink.net> wrote in message

news:yMv07.2313

Quote

> I didnt think I could run findclose until I was done with using it.  What
> happens if it is left open until the other items are finished?

Each call to FindFirst causes windows to allocate resources. These resources
are only released with a call to FindClose.

Re:Can you obtain the size of a file witout using reset?


If I were you I would manually watch the database for a bit - not from
a server but from a client to see whether the filesize actually grows
- there is this problem of the *non* updating of the file entry in the
directory until the files are closed or a pseudo close (flush) takes
place.

Assuming that the database is well written - it might be an idea - for
pure safety to let it live on a partition of under 1.5 Gb - so that in
the worst case it runs out of disk space.

On Wed, 04 Jul 2001 03:12:41 GMT, "Chuck Condron"

Quote
<cccondronspr...@earthlink.net> wrote:
>so far, with the code I posted in a post after yours, it seems to be working
>fine.  This routine runs once per hour and I see it reporting different
>sizes, so the database must be updating the size.  It is about 990 megs.
>This will be looking at a file size up to 2 gig.

>The reason we need this app is to monitor the size of this database (a
>Progress Database) that is part of some automation software that Radio
>Stations use.  Most stations that use automation, do not have any humans
>around or brain dead DJs hehehe.  Anyway, we have found that when this
>database gets to be 1.5 gigs...it will crash and sometimes it trashes itself
>in the process.  The company that makes the automation software has some
>reindexing utils that can be run to reduce the size of the database, but we
>want to warn an engineer or IT dude BEFORE it gets tooooo big...

>"Sundial Services" <info_...@sundialservices.com> wrote in message
>news:3B408834.7AC@sundialservices.com...
>> The size of a file may be found by querying the directory .. HOWEVER ..
>> the size stored there is usually the last size the file had when it was
>> last closed.  If a file has been recently created, its size is zero.  If
>> the file is currently open and has been extended, the directory-reported
>> size will not yet change.

>> Extremely large files can also present a problem.

>> The FindFirst(), FindClose(), et-al Delphi functions can be used to
>> obtain the directory-reported size of a file.

>> >Chuck Condron wrote:

>> > Is there anyway to obtain the filesize of a file without opening it? I
>read
>> > the docs on the filesize procedure and Reset procedure...Reset said, if
>the
>> > file is first open, it will then close it and reopen it. Filesize wants
>the
>> > file open. I want to watch the size of a database (Progress database).
>When
>> > my app needs to run, the database will already be open. I do not want to
>> > mess with the database in anyway, just want the size of it. Do I have
>any
>> > options?
>> ------------------------------------------------------------------
>> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
>> mailto:i...@sundialservices.com  (PGP public key available.)
>> > Fast(!), automatic table-repair with two clicks of the mouse!
>> > ChimneySweep(R):  "Click click, it's fixed!" {tm}
>> > http://www.sundialservices.com/products/chimneysweep

Re:Can you obtain the size of a file witout using reset?


On Wed, 04 Jul 2001 03:08:14 GMT, "Chuck Condron"

Quote
<cccondronspr...@earthlink.net> wrote:
>I have not written any error handling code at this time.  To look at how
>Delphi does it, check the example for the findfirst?

>I didnt think I could run findclose until I was done with using it.  What
>happens if it is left open until the other items are finished?

Nothing - unless you do a FindNext - the TSearchRecord is just a bit
of RAM - onse it is filled then it keeps its contents untill you
release it or re-use it.

Quote

>By puting it into a function, how does that help things?  This timer event
>is the only place its used.

Bet this is not the only Delphi App you have written or will write in
the future - every useful and generic utility is an investment for the
future.

Also it is really bad programming form to muddle up a significant
control routine with trivia - in this case you want to get the
FileSize - to the control routine it is irrelevant how you get it -
your 'utility' to get the file size either works or it does not.

The control routine is spectacularly uninterested in the other
contents of your instance of TSearchRec.

Quote

>I am only asking to learn.  I am in NO way a professional programmer, I only
>play one on the weekends hehehe...I just code a few things for our
>corporation from time to time to solve a few things we need.

I started that way 24 years ago - you are on a slippery slope.

Quote
>I appreciate the advise!!!

Good Luck
Quote

>"J French" <je...@iss.u-net.com> wrote in message
>news:3b41f99c.2897262@news.u-net.com...
>> If I were you I would do the FindClose immediately after the FindFirst
>> - also I would box it into a function - also how are you handling an
>> error from FindFirst - have a look at how Delphi does it.

>> On Tue, 03 Jul 2001 16:09:27 GMT, "Chuck Condron"
>> <chuckcond...@clearchannel.com> wrote:

>> >Hey gang..thanks for the help!  I actually had solved it on my own before
>I
>> >read all of your replys but here is what I came up with:

>> >procedure TForm1.Timer1Timer(Sender: TObject);

>> >begin

>> >findfirst('R:\Database\Prophet.Db',faAnyfile, sr);

>> >if sr.Size > (MaxSize.AsInteger*1000000) then begin

>> >Beep;

>> >Case DayOfWeek(now) of

>> >1: if Sun.Checked then btnSendMail.Click;

>> >2: if Mon.Checked then btnSendMail.Click;

>> >3: if Tue.Checked then btnSendMail.Click;

>> >4: if Wed.Checked then btnSendMail.Click;

>> >5: if Thu.Checked then btnSendMail.Click;

>> >6: if Fri.Checked then btnSendMail.Click;

>> >7: if Sat.Checked then btnSendMail.Click;

>> >end;

>> >end;//end if

>> >findclose(sr);

>> >end;

>> >(sr is declared globally)..

>> >"Chuck Condron" <chuckcond...@clearchannel.com> wrote in message
>> >news:pov%6.7496$ck5.750074@newsread2.prod.itd.earthlink.net...
>> >> Is there anyway to obtain the filesize of a file without opening it? I
>> >read
>> >> the docs on the filesize procedure and Reset procedure...Reset said, if
>> >the
>> >> file is first open, it will then close it and reopen it. Filesize wants
>> >the
>> >> file open. I want to watch the size of a database (Progress database).
>> >When
>> >> my app needs to run, the database will already be open. I do not want
>to
>> >> mess with the database in anyway, just want the size of it. Do I have
>any
>> >> options?

>> >> Chuck Condron

>> >> Regional IT Manager

>> >> Clear Channel Information Technologies

>> >> ChuckCond...@ClearChannel.com

>> >> AIM Screen Name: Vulcan39

Re:Can you obtain the size of a file witout using reset?


In article <3b42c7a6.1524...@news.u-net.com>, je...@iss.u-net.com (J French)
writes:

Quote
>Assuming that the database is well written - it might be an idea - for
>pure safety to let it live on a partition of under 1.5 Gb - so that in
>the worst case it runs out of disk space.

Nice bit of lateral thinking Jerry <g>.

Alan Lloyd
alangll...@aol.com

Go to page: [1] [2]

Other Threads