Solved

How to show files information.. TListView question

Posted on 2004-08-09
8
329 Views
Last Modified: 2010-04-05
How to show files information[filename, file size, File created date and time, File Defalt application] from selected folder with TListView component as Report?

Also pls show me a example of a selected file..


Thanks in advance!
0
Comment
Question by:goaman
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11760939
FindFirst/FindNext/FindClose...

var
  SearchRec: TSearchRec;
begin
  if ( FindFirst( 'C:\*.*', faAnyfile - faDirectory, SearchRec ) = 0 ) then begin
    repeat
      // Do something with data in searchrec.
      Memo1.Lines.Add(Format( 'Name: %s, size: %d, Full name: %s.', [ SearchRec.Name, SearchRec.Size, SearchRec.FindData.cFileName ] ));
    until ( FindNext( SearchRec ) <> 0 );
    FindClose( SearchRec );
  end;
end;

But the filedate/time must still be converted from a Windows-specific format to Delphi's TDateTime functionality.
0
 

Author Comment

by:goaman
ID: 11761306
Hi Alex,
This is good example, working just fine... I want this to work in TListView component which shows these all infromation as report... in 3 or 4 columns........



thanx in advance
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11761356
why not use a Tstringgrid? its an easy way of getting columns

the code would be

    StringGrid1.RowCount:= StringGrid1.RowCount+1;
    StringGrid1.cells[0,StringGrid1.RowCount-1]:= SearchRec.Name;
   StringGrid1.cells[0,StringGrid1.RowCount-1]:= SearchRec.Size;
  // ect.......

David
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Accepted Solution

by:
esoftbg earned 250 total points
ID: 11761416
Hi goaman, here is an example with TListView:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button_Scan: TButton;
    Edit_Count: TEdit;
    Edit_Path: TEdit;
    ListView: TListView;
    procedure FormCreate(Sender: TObject);
    procedure Button_ScanClick(Sender: TObject);
  private { Private declarations }
    Count_of_files: Integer;
    procedure Scan_Path(PathName: string);
  public  { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Count_of_files := 0;
end;

procedure TForm1.Scan_Path(PathName: string);
var
  Found:         Integer;
  Attr:          Integer;
  FName:         string;
  SearchRec:     TSearchRec;
var
  ListItem:      TListItem;
  S:             string;
  T:             string;
  ST:            TSystemTime;  // SystemTimeTypes
  FT:            TFileTime;    // FileTimeTypes
  DT:            TDateTime;
begin
  Attr := faDirectory;
  Found := FindFirst(PathName+'*.*', Attr, SearchRec);
  while (Found=0) do
  try
    if (((FileGetAttr(SearchRec.Name) and faArchive) > 0)
    or  ((FileGetAttr(SearchRec.Name) and faAnyFile) > 0)) then
      FName := PathName + SearchRec.Name;
    if FileExists(FName) then
    begin
      S := SearchRec.Name;
      //....
      ListItem := ListView.Items.Add;
      ListItem.Caption := S;
      T := IntToStr(SearchRec.Size);
      ListItem.SubItems.Add(T);
      FT := SearchRec.FindData.ftCreationTime;
      FileTimeToSystemTime(FT, ST);
      DT := SystemTimeToDateTime(ST);
      ListItem.SubItems.Add(FormatDateTime('yyyy/mm/dd hh:mm:ss', DT));
      //....
      Inc(Count_of_files);
    end;
  finally
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

procedure TForm1.Button_ScanClick(Sender: TObject);
var
  ListColumn:    TListColumn;
begin
  Edit_Count.Font.Color := clBlack;
  Application.ProcessMessages;
  if DirectoryExists(Edit_Path.Text) then
  try
    //....
    Application.ProcessMessages;
    //....
    ListView.Clear;
    ListView.Columns.Clear;
    //....
    ListColumn := ListView.Columns.Add;
    ListColumn.Caption := 'Filå Name';
    ListColumn.Width := 256;
    ListColumn := ListView.Columns.Add;
    ListColumn.Caption := 'Size';
    ListColumn.Width := 128;
    ListColumn := ListView.Columns.Add;
    ListColumn.Caption := 'Created';
    ListColumn.Width := 128;
    //....
    Scan_Path(Edit_Path.Text);
  finally
    Edit_Count.Text := IntToStr(Count_of_files) + ' file(s)';
    Edit_Count.Font.Color := clBlue;
    Count_of_files := 0;
  end;
end;

end.

//........

object Form1: TForm1
  Left = 224
  Top = 128
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Scan *.TXT files in given path'
  ClientHeight = 446
  ClientWidth = 632
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDefaultPosOnly
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button_Scan: TButton
    Left = 4
    Top = 4
    Width = 128
    Height = 25
    Caption = 'Scan Path'
    TabOrder = 0
    OnClick = Button_ScanClick
  end
  object Edit_Count: TEdit
    Left = 528
    Top = 8
    Width = 96
    Height = 17
    BorderStyle = bsNone
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    ReadOnly = True
    TabOrder = 1
  end
  object Edit_Path: TEdit
    Left = 136
    Top = 6
    Width = 384
    Height = 21
    TabOrder = 2
    Text = 'C:\Temp\'
  end
  object ListView: TListView
    Left = 4
    Top = 32
    Width = 620
    Height = 400
    Columns = <>
    GridLines = True
    ReadOnly = True
    TabOrder = 3
    ViewStyle = vsReport
  end
end
0
 

Author Comment

by:goaman
ID: 11761457
Hi esoftbg,
This is exactly what I was looking for.... Any Idea how to show current file images too? :D
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11761631
Hi goaman,
I know I don't deserve the points, because I can't show the current file images....
But the life is hard, I just can not do that for now....
Thanks for the Grade: A
Best Regards,
emil :D
0
 

Author Comment

by:goaman
ID: 11761713
esoftbg,
Anyway...  thanx man... My problem is solved.. :)


ps: You deserve these points.. cuz gave me what I was looking for.. :)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11762361
Too bad you already answered the question. To retrieve the file icon, include the ShellAPI unit in your project and use:

Icon := ExtractAssociatedIcon( HInstance,  PathName + SearchRec.Name, Idx );

to retrieve the icon for the file. You then have a handle to an icon (which you will have to release sooner or later) that you can use to paint in your listview.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month7 days, left to enroll

623 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