?
Solved

Create a Dir Listing as a Text File

Posted on 1997-07-27
4
Medium Priority
?
179 Views
Last Modified: 2010-04-04
Hi,
      I’m going to put together a program to replace one
at work.  What it does is take about 500 programs with
the names of ####.GL(#is a number) and renames them by removing the Ext part of the name.  Then it moves a set number of files to drive A: and props for another disk
this goes on until all files are copied over.  It also
makes a printout of  the disk directory on drive A: on
each disk. A little history on this program.  I work for
an Aircraft company as a CAD/CAM designer and there are programs for the CNC Mills.  We have to make backups to
keep on the floor so if needed they can be copied into the machines if needed..
   On the existing program I was able to make a text file
to use as a listing of the files to be moved.    
          Comamnd:=Dir C:\Temp\*.* /B >DirList.Doc
Then I user this file to Rename and move the files..
  Is there a way to get this dir listing in Delphi 3 like  the one I have above.  Then I can use it to rename and move the files.  Or if there is a better way to approach this project..

                                       Thanks
                                       Jim Zerbe
0
Comment
Question by:jim zerbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1339982
There are several ways to do this.
These examples are written on-the-fly ;-)
so there could be minor compilation problems:

1. Do it like you do it today:
   OK := (31 < WinExec(
     'cmd /c Dir C:\Temp\*.* /B >DirList.Doc', SW_HIDE
   ));
 or
   OK := (31 < WinExec(
     'command /c Dir C:\Temp\*.* /B >DirList.Doc', SW_HIDE
   ));

2. Totally programatically:
  procedure SaveDirContentsToFile(
    const Dir, Mask: string; const FileName: string;
    const FilesOnly: Boolean);
  var
    SearcRec  : TSearchRec;
    FileHandle: TextFile;
  begin
    try
      AssignFile(FileHandle, FileName);
      ReWrite(FileHandle);
      if FindFirst(Dir+'\'+Mask, faAnyFile, SearchRec)=0
      then repeat
        with SearchRec do begin
          if (((Attr and faDirectory)=faDirectory) xor FilesOnly)
          then WriteLn(FileHandle, Name);
        end;
      until FindNext(SearchRec)<>0;
      FindClose(SearchRec); // Return allocated memory
      CloseFile(FileHandle);
    except
      MessageBox('Couldn''t save directory to file!');
    end;
  end;

3. Totally programatically, with TStringList:
  procedure SaveDirContentsToFile(
    const Dir, Mask: string; const FileName: string;
    const FilesOnly: Boolean);
  var
    SearcRec  : TSearchRec;
    DirList   : TStringList;
  begin
    try
      DirList := TStringList.Create;
      DirList.Sorted := True;
      if FindFirst(Dir+'\'+Mask, faAnyFile, SearchRec)=0
      then repeat
        with SearchRec do begin
          if (((Attr and faDirectory)=faDirectory) xor FilesOnly)
          then DirList.Add(Name);
        end;
      until FindNext(SearchRec)<>0; // No more dir-entries
      FindClose(SearchRec); // Return allocated memory
      DirList.SaveToFile(FileName); // Use member functionallity
      Dirlist.Free; // Not needed further
    except
      MessageBox('Couldn''t save directory to file!');
    end;
  end;

Hope you can use this.

/// John
0
 

Author Comment

by:jim zerbe
ID: 1339983
Very Good thanks.  I did forget to add one thing will these work in NT work stations..
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1339984
Yes.
In fact only the second example will work on Windows 3.x
since "FindClose" is nonexistant in Delphi 1.x and since
"command" is replaced with "cmd" as the "DOS" command-interpreter
in NT.

Don't hesitate to ask if you run into more problems!

/// John

0
 

Author Comment

by:jim zerbe
ID: 1339985
Thanks for the speedy reply will try it out..
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question