TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

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

Print Reply
Simon Wright <[log in to unmask]>
Sun, 2 May 2004 07:00:56 +0100
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