Board index » delphi » Displaying subdirectories in a listbox...

Displaying subdirectories in a listbox...

Here's my problem. I have a directory structure something like this:

c:\maindir (main program directory, for exe and dlls)
c:\maindir\base (subdir holding database template)
c:\maindir\john \
c:\maindir\bill |---(user created subdirs holding user modified db's made
c:\maindir\jill /    using the template)

What happens is, the program loads, the user creates a new personal database
(simply a copy of the empty database found in the 'base' subdir placed into a
newly created subdir with the user's name), and the user modifies the file for
his purposes. The next time the program loads, the user should be able to pick
his personal file from a list box that, using the above directory tree, I
would like to look as follows:

 _____________
|john         |
|bill         |
|jill         |
|             |
|_____________|

What I need to know is:

How do I list just the users' subdir names and nothing else (i.e., I don't
want a regular directory pick box because it would show the 'base'
subdir...not to be messed with)? I figure I must need some sort of disk I/O
routine to scan the directory in some way. Delphi help was not helpful (not
surprising!).

Any ideas would be appreciated.

Kris Wilk
ReefNet Software
reef...@interlog.com

 

Re:Displaying subdirectories in a listbox...


In article <4ef0dd$...@steel.interlog.com>, reef...@interlog.com says...

Quote

>Here's my problem. I have a directory structure something like this:

>c:\maindir (main program directory, for exe and dlls)
>c:\maindir\base (subdir holding database template)
>c:\maindir\john \
>c:\maindir\bill |---(user created subdirs holding user modified db's made
>c:\maindir\jill /    using the template)

[cut]
>What I need to know is:

>How do I list just the users' subdir names and nothing else (i.e., I
don't
>want a regular directory pick box because it would show the 'base'
>subdir...not to be messed with)? I figure I must need some sort of disk
I/O
>routine to scan the directory in some way. Delphi help was not helpful
(not
>surprising!).

You can use the

  FindFirst, FindNext and FindClose functions to get directory-entries.
The function also gives you the attributes of the file.

Bye

Andreas Prucha

Re:Displaying subdirectories in a listbox...


Quote
reef...@interlog.com wrote:
>Here's my problem. I have a directory structure something like this:
>c:\maindir (main program directory, for exe and dlls)
>c:\maindir\base (subdir holding database template)
>c:\maindir\john \
>c:\maindir\bill |---(user created subdirs holding user modified db's made
>c:\maindir\jill /    using the template)
>What happens is, the program loads, the user creates a new personal database
>(simply a copy of the empty database found in the 'base' subdir placed into a
>newly created subdir with the user's name), and the user modifies the file for
>his purposes. The next time the program loads, the user should be able to pick
>his personal file from a list box that, using the above directory tree, I
>would like to look as follows:
> _____________
>|john         |
>|bill         |
>|jill         |
>|             |
>|_____________|
>What I need to know is:
>How do I list just the users' subdir names and nothing else (i.e., I don't
>want a regular directory pick box because it would show the 'base'
>subdir...not to be messed with)? I figure I must need some sort of disk I/O
>routine to scan the directory in some way. Delphi help was not helpful (not
>surprising!).
>Any ideas would be appreciated.
>Kris Wilk
>ReefNet Software
>reef...@interlog.com

procedure TForm1.Button1Click(Sender: TObject);
var
  SearchRec: TSearchRec;
  iError:integer;
begin
  iError:=FindFirst('c:\maindir\*.*', faDirectory, SearchRec);
  ListBox1.Clear;
  while iError=0 do begin
    if ((SearchRec.Attr and faDirectory)<>0) and
     (SearchRec.Name<>'BASE')
    then begin
      ListBox1.Items.Add(SearchRec.Name);
    end;
    iError:=FindNext(SearchRec);
  end;
end;

Hasn't this question been repeated a while?
HTH take care of it.

Regards, Bengt Richter

Other Threads