View Full Version : need help with file path !!!
GoOgLe
03-28-2008, 04:09 AM
trying to show just the file name noe the path but i couldnt manage with this code, i have tried many different ways but no...
http://img176.imageshack.us/img176/1654/errornt5.jpg
Global Functions Code:
function GetFilename(sFolderPath)
sFilename = "";
nInd = String.ReverseFind(sFolderPath, "\\", false);
if (nInd ~= -1) then
sFilename = String.Mid(sFolderPath, nInd + 1, -1);
end
if (sFilename == "") then
sFilename = sFolderPath;
end
return sFoldername;
end
Page On Preload Code :
myDocsFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
Folder.Create(myDocsFolder.."\\Available Files");
tblMenu = Application.GetMenu();
local nNewitem = Table.Count(tblMenu)+1;
tblMenu[nNewitem] ={};
tblMenu[nNewitem].Text = "&Available Files";
tblMenu[nNewitem].ID = 1000;
tblMenu[nNewitem].Checked = false;
tblMenu[nNewitem].Enabled = true;
tblMenu[nNewitem].SubMenu = {};
local tFiles = File.Find(myDocsFolder.."\\Available Files", "*.exe");
if (tFiles) then
for n, cFolderPath in tFolderPaths do
local x = 0;
for x = 1,Table.Count(tFiles) do
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = tFiles[x];
tblMenu[nNewitem].SubMenu[x].ID = 1000+x;
tblMenu[nNewitem].SubMenu[x].Checked = false;
tblMenu[nNewitem].SubMenu[x].Enabled = true;
end
Application.SetMenu(tblMenu, GetFilename(cFolderPath), cFolderPath);
end
end
longedge
03-28-2008, 04:50 AM
You need to use String.SplitPath for example where you've set a variable str_foundfile -
split_path = String.SplitPath(str_foundfile);
file_name=split_path.Filename
Label.SetText("Label1", file_name);
--or to display the filename together with the extension
file_extension=split_path.Extension
full_name=file_name..file_extension
Label.SetText("Label2", full_name);
GoOgLe
03-28-2008, 08:59 AM
it doesnt work... i didnt get it !!!
myDocsFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
Folder.Create(myDocsFolder.."\\Addons");
tblMenu = Application.GetMenu();
local nNewitem = Table.Count(tblMenu)+1;
tblMenu[nNewitem] ={};
tblMenu[nNewitem].Text = "&Addons";
tblMenu[nNewitem].ID = 1000;
tblMenu[nNewitem].Checked = false;
tblMenu[nNewitem].Enabled = true;
tblMenu[nNewitem].SubMenu = {};
local tFiles = File.Find(myDocsFolder.."\\Addons", "*.exe");
if (tFiles) then
split_path = String.SplitPath(tFiles);
file_name=split_path.Filename
local x = 0;
for x = 1,Table.Count(tFiles) do
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = split_path.Filename;
tblMenu[nNewitem].SubMenu[x].ID = 1000+x;
tblMenu[nNewitem].SubMenu[x].Checked = false;
tblMenu[nNewitem].SubMenu[x].Enabled = true;
end
Application.SetMenu(tblMenu);
else
end
jassing
03-28-2008, 09:18 AM
it doesnt work... i didnt get it !!!
Google:
In another post, I provided you with a function File.ExtensionOnly() that would do what you want -- copy that code into the GlobalFunctions section and wrap it around the menu.text line.
GoOgLe
03-28-2008, 09:33 AM
i tried that jassing... i think thats what u mean !!! i got error
Global Functions:
function File.NameOnly( cFile )
local tFile = String.SplitPath( cFile );
return tFile.Filename .. tFile.Extension;
end
On Preload:
myDocsFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
Folder.Create(myDocsFolder.."\\Addons");
tblMenu = Application.GetMenu();
local nNewitem = Table.Count(tblMenu)+1;
tblMenu[nNewitem] ={};
tblMenu[nNewitem].Text = "&Addons";
tblMenu[nNewitem].ID = 1000;
tblMenu[nNewitem].Checked = false;
tblMenu[nNewitem].Enabled = true;
tblMenu[nNewitem].SubMenu = {};
local tFiles = File.Find(myDocsFolder.."\\Addons", "*.exe");
if (tFiles) then
local x = 0;
for x = 1,Table.Count(tFiles) do
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = File.NameOnly( cFile );
tblMenu[nNewitem].SubMenu[x].ID = 1000+x;
tblMenu[nNewitem].SubMenu[x].Checked = false;
tblMenu[nNewitem].SubMenu[x].Enabled = true;
end
Application.SetMenu(tblMenu);
else
end
GoOgLe
03-28-2008, 03:01 PM
still need help...:o
jassing
03-28-2008, 03:08 PM
still need help...:o
Google - have you read the help on String.SplitPath() ? This is the function you'll need to work with.
GoOgLe
03-28-2008, 03:17 PM
i read it but i didnt really really understand it jassing
jassing
03-28-2008, 03:33 PM
i read it but i didnt really really understand it jassing
Sorry -- I'm not sure how else to explain it to you.
jassing
03-28-2008, 03:53 PM
How's this:
how's this:
cFile = "c:\somedirectory\file.ext"
?String.SplitPath(cFile).Filename
"file"
?String.SplitPath(cFile).Extension
".ext"
does that make sense to you?
If not; I'm out of ideas to explain it...
longedge
03-28-2008, 05:11 PM
it doesnt work... i didnt get it !!!
You didn't allow for the fact that File.Find returns a table so the line
split_path = String.SplitPath(tFiles);
won't work. Moving the code inside the loop and then adding the counter [x] to specify which element of the table is required should work OK -
tblMenu = Application.GetMenu();
local nNewitem = Table.Count(tblMenu)+1;
tblMenu[nNewitem] ={};
tblMenu[nNewitem].Text = "&Addons";
tblMenu[nNewitem].ID = 1000;
tblMenu[nNewitem].Checked = false;
tblMenu[nNewitem].Enabled = true;
tblMenu[nNewitem].SubMenu = {};
local tFiles = File.Find(myDocsFolder.."\\Addons", "*.exe");
if (tFiles) then
local x = 0;
for x = 1,Table.Count(tFiles) do
split_path = String.SplitPath(tFiles[x]);
file_name=split_path.Filename
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = split_path.Filename;
tblMenu[nNewitem].SubMenu[x].ID = 1000+x;
tblMenu[nNewitem].SubMenu[x].Checked = false;
tblMenu[nNewitem].SubMenu[x].Enabled = true;
end
Application.SetMenu(tblMenu);
else
end
GoOgLe
03-29-2008, 03:43 AM
thanks for ur help longedge
longedge
03-29-2008, 04:39 AM
thanks for ur help longedge
You are very welcome, hope you understand my reasoning for using the forum :) :yes
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.