TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
Simon Wright <[log in to unmask]>
Date:
Sun, 2 May 2004 07:00:56 +0100
In-Reply-To:
<[log in to unmask]> (message from Rick Duley on Mon, 26 Apr 2004 14:16:10 +0800)
X-To:
Reply-To:
Simon Wright <[log in to unmask]>
Parts/Attachments:
text/plain (43 lines)
> From: Rick Duley <[log in to unmask]>

> I am currently working on some language analysis software (both
> natural language and code) for use in my doctoral research.  It
> would be ideal if I could set an application up to work its way
> through all the files in a folder automatically - that is, set it to
> work on a folder full of files and it will automatically process
> each of the files in the folder in succession.
>
> Does anyone have any idea of how this can be done?

This is a recursive directory search using GNAT.Directory_Operations:

   procedure Scan_Directory (Named : Dir_Name_Str) is
      Wd : Dir_Type;
   begin
      Open (Dir => Wd,
            Dir_Name => Named);
      declare
         Str : String (1 .. 1024);
         Last : Natural;
      begin
         loop
            Read (Dir => Wd,
                  Str => Str,
                  Last => Last);
            exit when Last = 0;
            if Str (1 .. Last) /= "." and Str (1 .. Last) /= ".." then
               if Is_Directory (Named & Str (1 .. Last)) then
                  Scan_Directory
                    (Named & Str (1 .. Last) & Directory_Separator);
               else
                  Save_File (Named & Str (1 .. Last));
               end if;
            end if;
         end loop;
      end;
      Close (Dir => Wd);
   end Scan_Directory;

Save_File is the place where the work gets done.
Not so sure about the 1024!

ATOM RSS1 RSS2