Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Create a Dir Listing as a Text File

Posted on 1997-07-27
4
Medium Priority
?
181 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 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