comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@adaos.worldonline.co.uk>
Subject: Re: file list in a directory
Date: Sat, 17 Mar 2001 17:45:55 -0000
Date: 2001-03-17T17:45:55+00:00	[thread overview]
Message-ID: <9907tp$3ula5$1@ID-25716.news.dfncis.de> (raw)
In-Reply-To: wccelvxqxrj.fsf@world.std.com

Is there a working doucment on this on the Internet anywhere?

One idea that occurred to me as to how an implementation could supply this
sort of facility, without actually requiring a special package, would be to
provide a special syntax for the file name when opening or creating a text
file, where the relevant names or other data/parameters were output/input as
lines of text. For example:

with Ada.Text_IO; use Ada.Text_IO;
procedure List_Ada is
   Name: String(1..200);
   Last: Natural;
   Search: File_Type;
begin
   Open(Search,In_File,"dir:*.ads;*.adb//source/ada/");
   Get_Line(Search,Name,Last);
   Put_Line(Name(1..Last));
   Close(Search);
end;

Operations such as copying, linking, archiving/backup, and inquiry and
update of attributes could be provided in a similar way. This technique
makes use of the file I/O idiom to provide a ready iterator. In particular
it says when a single search begins and ends (at opening and closing), so
that the list can be 'frozen' (or the directory locked) during the search.
It could also help with debugging, and help facilitate ersatz functionality.

Obviously, a definition of a standard name syntax would be advantageous.
This would be a technique that could have the advantage of being largely
language-independent.

A copying example might be:

with Ada.Text_IO; use Ada.Text_IO;
procedure Copy_Safely is
   Name: String(1..200);
   Last: Natural;
   Search, Copier: File_Type;
begin
   Open(Search,In_File,"dir:*.ads;*.adb//source/ada/");
   Create(Copier,Out_File,"copy:|//source/ada");
   Get_Line(Search,Name,Last);
   Put_Line(Copier, Name(1..Last) & "|backup/" & Name(1..Last) );
   Close(Search);
   Close(Copier);
end;

When the Copier file is closed, the copy operations are performed,
preferably with all-or-nothing semantics (if something goes wrong, an
exception is raised).

NB: These examples don't have the checking they should.

--
Nick Roberts
http://www.AdaOS.org



"Robert A Duff" <bobduff@world.std.com> wrote in message
news:wccelvxqxrj.fsf@world.std.com...
> Pascal Obry <p.obry@wanadoo.fr> writes:
>
> > Ada can't do that. Some program just don't have access to a file system
> > (e.g. embedded programs).
>
> Not a very good excuse, I think.  Ada has Text_IO, after all.
>
> The ARG is working on a portable (standard) Directory_Operations
> package, but it won't happen quickly.
>
> - Bob





  parent reply	other threads:[~2001-03-17 17:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-16 18:19 file list in a directory EtienneB
2001-03-16 18:31 ` Pascal Obry
2001-03-16 20:12   ` Robert A Duff
2001-03-17 10:09     ` Pascal Obry
2001-03-17 17:45     ` Nick Roberts [this message]
2001-03-17 18:08       ` Randy Brukardt
2001-03-17 19:57       ` Georg Bauhaus
2001-03-19 10:46       ` Jean-Pierre Rosen
2001-04-08  3:18         ` srini
2001-04-09  9:34           ` Jean-Pierre Rosen
2001-03-16 19:07 ` tmoran
2001-03-16 21:19   ` EtienneB
2001-03-17  0:53     ` David C. Hoos, Sr.
2001-03-17  2:50     ` DuckE
2001-03-17 12:30       ` Staffan Dittmer
2001-03-17 10:10     ` Pascal Obry
2001-03-16 21:19 ` EtienneB
2001-03-19  9:23 ` Martin Dowie
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox