Board index » delphi » FileListbox returns wrong directory

FileListbox returns wrong directory

I am using  D5 pro
I have a TFileListBox component on a form.
When the form opens it reads an ini file, takes a directory name, and sets
the mask property accordingly.
The list of files shown is fine.
For example the listbox.mask  may be
"C:\backup\something*.bak"
When I select a file from the list, and use:

  restorefile:= listbox.FileName;
    showmessage( restorefile);
I am getting the delphi run time path ' D:\program
files\borland\delphi5\projects\allotments\something528.bak'

Why am I getting the wrong path?
How do I get the correct file name, or even just the filename without any
directories?

Am I using the best component for this?

regards
John Evans
Technical Director
Clear Advantage Ltd

 

Re:FileListbox returns wrong directory


The delphi runtime path is the default path.
You have to set it first :

filelistbox1.directory:='C:\backup\';
filelistbox1.mask:='*.bak';

in the filelistbox1change_event(..)
  if filelistbox1.itemindex>=0 then begin
   restorefile:=filelistbox1.filename;
..

and look up the extractfilename() function

Rene
--
Ing. Buero R.Tschaggelar - http://www.ibrtses.com

Quote
John Evans wrote:
> I am using  D5 pro
> I have a TFileListBox component on a form.
> When the form opens it reads an ini file, takes a directory name, and sets
> the mask property accordingly.
> The list of files shown is fine.
> For example the listbox.mask  may be
> "C:\backup\something*.bak"
> When I select a file from the list, and use:

>   restorefile:= listbox.FileName;
>     showmessage( restorefile);
> I am getting the delphi run time path ' D:\program
> files\borland\delphi5\projects\allotments\something528.bak'

> Why am I getting the wrong path?
> How do I get the correct file name, or even just the filename without any
> directories?

> Am I using the best component for this?

Other Threads