Solved

Create a Dir Listing as a Text File

Posted on 1997-07-27
4
175 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
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 50 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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