?
Solved

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

Posted on 2002-07-02
5
Medium Priority
?
244 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
[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
5 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 150 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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
Course of the Month9 days, 22 hours left to enroll

762 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