PDA

View Full Version : Example : Populate a tree from Files in a Folder


TristanD
01-20-2007, 05:39 AM
The is an project i made on request.. It populates a tree object with files from a folder and when double click on a node it open the file

How to set it up Yourself :

Create a tree object..

On Global Functions:
function GetFolderContentsFromDialog()
folderbrowse = Dialog.FolderBrowse("Please select a folder:", _SourceDrive);
Zip = File.Find(folderbrowse, "*.rar", true, false, ShowSearchProgress, nil);
if Zip then
for i,v in Zip do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree1", "3", tblNodeData);
end
end
end

function GetFolderContents()
Zip = File.Find(_SourceFolder, "*.rar", true, false, ShowSearchProgress, nil);
if Zip then
for i,v in Zip do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree1", "3", tblNodeData);
end
end
end

function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree1");
node = Tree.GetNode("Tree1", sel_node);
node_data = node.Data
File.Open(node_data, "", SW_SHOWNORMAL);
end

On Show (two options possible)
1 Populate from a folder chosen with a dialog
GetFolderContentsFromDialog()

2 Populate From the sourcefolder
GetFolderContents()

Tree, On Double Click
RunNodeFile()

Thats it

If you dont feel like copy and pasting the whole time then use my prebuild project ;)

1skram323
04-11-2007, 11:03 PM
I am pretty new at this and was playing with the code that you posted.

could you please show me how to change the File.Run to file.copy to a set location?

thank you in advance, I am a novice coder and need all the help I can get.
Mark

TristanD
04-16-2007, 09:31 AM
On global function, change the red line into the blue one
function GetFolderContentsFromDialog()
folderbrowse = Dialog.FolderBrowse("Please select a folder:", _SourceDrive);
Zip = File.Find(folderbrowse, "*.rar", true, false, ShowSearchProgress, nil);
if Zip then
for i,v in Zip do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree1", "3", tblNodeData);
end
end
end

function GetFolderContents()
Zip = File.Find(_SourceFolder, "*.rar", true, false, ShowSearchProgress, nil);
if Zip then
for i,v in Zip do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree1", "3", tblNodeData);
end
end
end

function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree1");
node = Tree.GetNode("Tree1", sel_node);
node_data = node.Data
File.Open(node_data, "", SW_SHOWNORMAL);
File.Copy(Node_Data, "C:\\MyDir\\", true, true, false, true, nil);
end

this will copy the selected file to your C drive

1skram323
04-17-2007, 12:44 AM
Thank you, I had tried that but had left something out!

I appreciate the help!
Mark

HCASDG
01-22-2008, 11:37 AM
Thanks for the code.

Any suggestions on how to enhance the GetFolderContents function to alphabetically sort the files that are retrieved?

TimeSurfer
01-22-2008, 01:22 PM
you really shouldnt have to make it sort them. have the function load the files into a listbox or tree object and enable sort under object properties. you may also have to use set properties for your object in an on show or preload event. if you need any help let me know and i will try to get you a quick example

pakapaka
06-02-2008, 01:52 PM
I am using the example project made by TristanD (..many many thanks if you are still around the Forum). The link is here

http://www.indigorose.com/forums/showthread.php?t=18569&highlight=tree+node+open+file

Now I need to make a couple of slight modifications to the code as follows:

1) Instead of the default folder (c:\root..) I need to define a specific folder under the \autoplay\docs\ folder
2) When the tree is populated I need to hide the file extension (i.e not show *.pdf etc)
3) When I press a button, I need to refresh the tree (for the same folder) without showing a dialog box.

Perhaps I should mention that I am not using "rootfolder" input box or the "change" button inside the project

Can anybody help...I am not a programmer so your assistance is greatly appreciated.

Thanks
Pakapaka

Imagine Programming
06-03-2008, 06:29 AM
I don't think that thierry (Tristan) is still on the forum, he is programming in VB now... ah well, he made great examples ^^ i taught me programming in lua lol

TristanD
07-03-2008, 05:34 AM
I don't think that thierry (Tristan) is still on the forum, he is programming in VB now... ah well, he made great examples ^^ i taught me programming in lua lol

Yeah i've switched from ams to Vb.Net but hey, im still around, willing to help wherever i can and i've learned alot in the mean time:yes

pakapaka
07-03-2008, 01:09 PM
Thanks Tristan...I will rewrite my question and repost it
Maybe you can help

TristanD
07-05-2008, 04:18 PM
Go Ahead, Repost