Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-07-02
5
Medium Priority
?
245 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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