Solved

Read the directory for file names ( preview, rename, delete).

Posted on 2002-07-02
5
238 Views
Last Modified: 2010-04-04
I am looking for a piece of code that might help me to start with following issues.
The programme must be able
1)To read a directory and list all files in the directory (with particular extension for example only html files).
2)allow the user to select a file for
  Preview, rename and deletion

Thank you in advance

0
Comment
Question by:Cyrus2k
5 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7124295
Cyrus2k,

This is one simple way to do it:

1. Place DriveComboBox1, DirectoryListBox1 and FileListBox1 on the form.

2. Place 3 buttons and name them Preview, Rename and Delete

3. Set following properties (from object inspector):
- DriveComboBox1.DirList:=DirectoryListBox1;
- DirectoryListBox1.FileList:=FileListBox1;

4. Set Mask property of FileListBox1; to whatever you like. For your example:
FileListBox1.Mask:='*.htm;*.html;*.mht';

5. Set DirectoryListBox1.Directory (from code) to whatever initial dir you wish

6. When you click on any of the buttons you can access currently selected file by:
   FileListBox1.FileName
.. and do any operation you like with it.



0
 
LVL 17

Expert Comment

by:geobul
ID: 7124326
Hi,
Another way: drop a TListBox and a button on a form. Then:

procedure GetFiles(DirStr, Mask: String; List: TStrings);
var
  DirInfo: TSearchRec;
  R: Integer;
begin
  R := FindFirst(DirStr + Mask, faAnyfile, DirInfo);
  if R = 0 then
  begin
    repeat
      if not (DirInfo.Attr and faDirectory) <> 0 then List.Add(DirStr + DirInfo.Name);
      R := FindNext(DirInfo);
    until R <> 0;
    FindClose(DirInfo);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  GetFiles('C:\MyDir\', '*.htm?', ListBox1.Items);
end;

// write a TListBox.OnClick event handler like:

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  with ListBox1 do begin
    if ItemIndex >= 0 then begin
      // do something with the selected file
      ShowMessage(Items[ItemIndex]);
    end;
  end;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 7124341
Instead of using ListBox1.OnClick you may add a TPopupMenu with Items [Preview, Rename, Delete]. Set ListBox1.PopupMenu to PopupMenu1 and write PopupMenu events. For example Preview may look like:

procedure TForm1.Preview1Click(Sender: TObject);
begin
  ShellExecute(0, 'open', PChar(ListBox1.Items[ListBox1.ItemIndex]), nil, nil, SW_SHOWNORMAL);
end;

Regards, Geo
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 7124482
you could use an opendialog, the user selects a file to view or simply renames or deletes fom within the dialog.
place an OpenDialog on the form and something like this to call it

  with OpenDialog1 do
  begin
    InitialDir := 'c:\'; // start dir
    FileName := ''; // file to start with
    DefaultExt := ''; // ext to start with
    Title := 'Select a file to view, rename or delete';
    Filter := 'All files (*.*)|*.*'; // filter for all
    Options := [ofEnableSizing,ofHideReadOnly]; // etc
    if Execute then
    begin
      DisplayMyFileOrWhatever(FileName);
      // etc.
    end;
  end;
0
 
LVL 1

Author Comment

by:Cyrus2k
ID: 7129087
It is a good way of doing this problem.
Thank you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now