View Full Version : String.SplitPath
sside
10-07-2004, 11:14 AM
If i split the path for a single file in order to get file name and file extension i use this code;
--------------------------------------------------------------
resFind = File.Find("data", "1.txt", false, false, nil);
resSplitPath = String.SplitPath(resFind[1]);
result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, "");
--------------------------------------------------------------
But how must be this code adapted when the search returns a table of data?
--------------------------------------------------------------
resFind = File.Find("data", "*.txt", false, false, nil);
resSplitPath = String.SplitPath(resFind[1]);
result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, "");
--------------------------------------------------------------
Thank you
Sside
TJ_Tigger
10-07-2004, 11:49 AM
Sside
Since the File.Find returns a table you can use a for loop to enumerate the table and add each item one at a time. Here is an example for the code.
resFind = File.Find("data", "*.txt", false, false, nil);
for index, value in resFind do
resSplitPath = String.SplitPath(resFind[index]);
result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[index]);
end
I usually will add the full path for the file into the Data section of the listbox as you can see above, that way if I want to open the file I can use that to open it without having to search for the full path again.
Tigg
sside
10-07-2004, 12:18 PM
Thank you TJ_Tigger
It works, perfect.
The idea of the path in the data section is also very useful. Thanks for the idea.
I try to loop it (for i, v.../ for n=1...) but no luck.
Anyway now it works fine.
Once again thank you for your time
Sside
TJ_Tigger
10-07-2004, 01:54 PM
Thank you TJ_Tigger
It works, perfect.
The idea of the path in the data section is also very useful. Thanks for the idea.
I try to loop it (for i, v.../ for n=1...) but no luck.
Anyway now it works fine.
Once again thank you for your time
Sside
Either of those should work. I find that the for i,v in table do works very well but for n = 1,TableCount(table) do should work as well
sside
10-07-2004, 02:17 PM
Hello TJ_Tigger,
Yes they work fine as well,
--------------------------------------------------------------
resFind = File.Find("data", "*.txt", false, false, nil);
for i, v in resFind do
resSplitPath = String.SplitPath(resFind[i]);
result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[i]);
end
--------------------------------------------------------------
resFind = File.Find("data", "*.txt", false, false, nil);
for n=1, Table.Count(resFind) do
resSplitPath = String.SplitPath(resFind[n]);
result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[n]);
end
---------------------------------------------------------------
Thanks a lot for the help
Sside
sside
10-07-2004, 07:36 PM
TJ_Tigger
One more question,
I have a ini file with paths to be searched for, it could be 3, 4, 5 ... paths
1-I search for the value names (INIFile.GetValueNames) in order to get their values.
2-I search for values (INIFile.GetValue) in order to get the paths to search for.
3-I want to search these paths for files.
-----------------------------------------------------------------------
resValues = INIFile.GetValueNames("data\\1.ini", "paths");
for i, v in resValues do
resPaths = INIFile.GetValue("data\\1.ini", "paths", resValues[i]);
resSearch = File.Find(resPaths, "*", false, false, nil);
end
for i, v in resSearch do
result = ListBox.AddItem("ListBox3", v, "");
end
------------------------------------------------------------------------
Only the last value will be stored in resPaths
So the question is how can i search these paths ?
Thanks a lot
Sside
TJ_Tigger
10-07-2004, 11:25 PM
Probably not the best thing to do but this is what I would probably do.
resValues = INIFile.GetValueNames("data\\1.ini", "paths");
resSearch = {};
for i, v in resValues do
resPaths = INIFile.GetValue("data\\1.ini", "paths", resValues[i]);
tempresSearch = File.Find(resPaths, "*", false, false, nil);
if tempresSearch then
for ti, tv in tempresSearch do
--This insert command will take all the items found if any and place them
-- in the first place position pushing everything else down in the table.
Table.Insert(resSearch, 1, tv)
end
end
for i, v in resSearch do
result = ListBox.AddItem("ListBox3", v, "");
end
That is the best I can come up with right now. I might find something better tommorrow.
Tigg
sside
10-08-2004, 11:16 AM
Hello Tigg
It works fine. Thanks a lot for your help. I'm new to this table thing so.. that's why so many questions.
Once again thank you.
Sside
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.