Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-02

How to assign a file? Please help

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Hankovec

Hello,
I've a problem:
I'm writing simple routine for copying files (it's in documentation too).

If the type of variable for statement 'assign' is TEXT - it's OK. 'Reset' opens it, 'close' closes it even for many files.

B U T
If it's 'FILE' like in example in doc, and I try to copy more files, it crashes on error - too much files are opened. And I use only Assign,Reset and Close! So after 'close' on filetype 'FILE' it is still opened ?!!!

Fragment:
...
Var
    Fin,fout : text;
begin
  Assign (Fin,name);
  Reset(Fin);
 ....
  close (fin);
end;

This works on many files OK. If I change it to
Fin,fout: file;
after 5 proofs it will crash (5 is the maximum of simultaniously opened files under my Win NT)
I have the ver. 1.0.2 of compiler.

Can anybody tell me, how to copy many of files?

Thanks a lot and have a good day

Martin

Reply by email

Tobias Hermann
to Martin Hankovec

if you use FILE as type,you have to set the record size to 1:

reset(fin, 1);

the default record size is 128 bytes...

Tobi

Earlier message 50 lines
----- Original Message ----- From: Martin Hankovec To: Sent: Wednesday, February 14, 2001 9:05 AM Subject: [fpc-pascal]How to assign a file? Please help > Hello, > I've a problem: > I'm writing simple routine for copying files (it's in documentation too). > > If the type of variable for statement 'assign' is TEXT - it's OK. 'Reset' > opens it, 'close' closes it even for many files. > > B U T > If it's 'FILE' like in example in doc, and I try to copy more files, it crashes > on error - too much files are opened. And I use only Assign,Reset and Close! > So after 'close' on filetype 'FILE' it is still opened ?!!! > > Fragment: > ... > Var > Fin,fout : text; > begin > Assign (Fin,name); > Reset(Fin); > .... > close (fin); > end; > > This works on many files OK. If I change it to > Fin,fout: file; > after 5 proofs it will crash (5 is the maximum of simultaniously opened files > under my Win NT) > I have the ver. 1.0.2 of compiler. > > Can anybody tell me, how to copy many of files? > > Thanks a lot and have a good day > > Martin > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >

Reply by email

Martin Hankovec
if you use FILE as type,you have to set the record size to 1:

Yes, of course, I didn't write it to email. But it doesn't work with it.

Martin

Reply by email

Pierre Muller
to Martin Hankovec

At 12:07 14/02/01 , vous avez écrit:

>if you use FILE as type,you have to set the record size to 1: Yes, of course, I didn't write it to email. But it doesn't work with it.

Could you please provide a compilable source
as small as possible that demonstates your problem ?

Reply by email

Martin Hankovec
Could you please provide a compilable source as small as possible that demonstates your problem ?

The source can be found in documentation under
BlockRead - example. But I use a unit for delivering of all files in directories and subdirectories,so it's hard to give all the source (maybe on private mail).

If You try to run the example from documentation (copying files, example from BlockRead in System unit) and run it on 10 or more files, it will copy only some files (by me on NT4.0 only five files, on Win9x maybe more). Then it will give an error of "Too many files open". (Every file is assigned,opened and CLOSED!!!).

Now I tried to use the Sysutils unit,and this work fine.

Simple example,that didn't work for me,and demonstrates the error: ...
procedure test(name:string);
var fin:file;
begin
assign(fin,name); {assign it}
reset(fin,1); {open for reading}

  if ioresult0 then writeln('Error!!');
  close(fin);     {do nothing and close it immediately}

end;
...
And call this procedure on many files. After some openings it returns an error (Too many files opened).

With Sysutils (fileread,fileopen etc.) it works, maybe an error in System unit ?

Thanks for advice.

Martin H.

Reply by email

Marco van de Voort
to Martin Hankovec
Show quoted text 14 lines
... procedure test(name:string); var fin:file; begin assign(fin,name); {assign it} reset(fin,1); {open for reading} if ioresult0 then writeln('Error!!'); close(fin); {do nothing and close it immediately} end; ... And call this procedure on many files. After some openings it returns an error (Too many files opened). With Sysutils (fileread,fileopen etc.) it works, maybe an error in System unit ?

Do you do a recursive search with findfirst in the code that calls the above procedure? If so, are all findfirst matched with a findclose?

Reply by email

Martin Hankovec
Do you do a recursive search with findfirst in the code that calls the above procedure? If so, are all findfirst matched with a findclose?

I think - yes. It is working with Sysutils OK.
I tested my recursive unit for a long time,all allocated memory is freed after end. I have no idea, why this didn't work.

When I tested the code from Pierre, it works OK. Excuse me, if I'm wrong. Maybe some "misscompatibility" with my own unit. I take a got this error a long ago too,and must use the Sysutils instead of Dos. But I don't remember conditions.

I put attention on my dir-seeking unit (but it's stable on 150000 of files, thousends of dirs and about 6 GB of data, I've tested on our net).

Maybe bad allocation, good idea, I try it found.

Thanks a lot to all who spend their time on my problem. I try to find more conditions of missbehaviour.

Have a good day
With best greetings
Martin H.

Reply by email