Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Menu from Directory Structure

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm looking at this problem on the side of my usual workload and would appreciate any pointers with it.
I want to be able to point my application at a directory (network or local) and then generate a Menu from the file structure found. For instance if I was to point the application at a local folder (for instance C:\Steve') the program would then search this folder (and subfolders) constructing a Menu (for the form) with links to all the '.txt' files (or '.doc' files maybe). That is I would get a menu item for each subfolder found in the top level folder, and off each of these further menu items (in the form of a submenu) and so on, with final links to the text files (admiteddly these may lie in the top level folder).
Can anyone suggest a way I may start to look at this, constructing the Menu dynamically according to the folder structure (subfolders within folders, etc) with final options off these menus such that they can be clicked and 'NotePad' started with these files opened for review/editing.
Any help would be appreciated.
Thanks in advance
Steve
 
I would search through the root directory for all files/directories using FindFirst/FindNext, adding each file as a menu item (see the Delphi help file for help on adding menu items dynamically) and adding each directory as a submenu, recursively calling the above method for each directory you find.

Every time you create a menu item for a file, set its Tag property to be a unique incremental value, and use this to reference, say, a TStringList of filenames. You can then have one common event handler for all of the menu items that simply retrieves the Tag value of the Sender and ShellExecutes the relevant path/filename in your stringlist.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top