PDA

View Full Version : need help String.SplitPath


GoOgLe
03-24-2008, 03:54 AM
i wanna show only name and extension or just name !!!!

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
for j,Path in tFiles do
FileParts = String.SplitPath(Path);
tFiles_File = FileParts.Filename..FileParts.Extension;
end
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);
else
end

rexzooly
03-24-2008, 04:41 AM
i wanna show only name and extension or just name !!!!

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
for j,Path in tFiles do
FileParts = String.SplitPath(Path);
tFiles_File = FileParts.Filename..FileParts.Extension;
end
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);
else
end

try the string

here is what the help file says one it:
Debug.ShowWindow(true); --Shows the debug window.
path_parts = String.SplitPath("C:\\MyFolder1\\MyFolder2\\myfile.exe");
Debug.Print(path_parts.Drive.."\r\n");
Debug.Print(path_parts.Folder.."\r\n");
Debug.Print(path_parts.Filename.."\r\n");
Debug.Print(path_parts.Extension.."\r\n");

GoOgLe
03-24-2008, 04:45 AM
thanks rexzooly but i dont want to show debug window...

rexzooly
03-24-2008, 04:47 AM
thanks rexzooly but i dont want to show debug window...

just take that out of the code :)


////EDITE

path_parts = String.SplitPath("C:\\MyFolder1\\MyFolder2\\myfile.exe");

sFilename = path_parts.Filename.path_parts.Extension

try that

but from what i can see you already have this on your code ???

GoOgLe
03-24-2008, 08:15 AM
i tried it m8... it doesnt work !!!

Esfahan
03-24-2008, 08:22 AM
edit this example for yourself:
path_parts = String.SplitPath("C:\\myfile.exe");
name_ext=(path_parts.Filename..path_parts.Extensio n)

Imprtant :
1- no space in Extension word . when i paste it in here , it convert!
2-yuo can replace a variable in ("C:\\myfile.exe");!!!!!!!

GoOgLe
03-24-2008, 08:32 AM
still the same... i see the whole path !!!

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
path_parts = String.SplitPath(myDocsFolder.."\\Addons", "*.exe");
name_ext=(path_parts.Filename..path_parts.Extensio n)
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);

else
end

RizlaUK
03-24-2008, 10:39 AM
RTFM :eek: RTFM :eek: RTFM :eek: RTFM

its showing the full path coz you are telling it to

change:
tblMenu[nNewitem].SubMenu[x].Text = tFiles[x];


to:
tblMenu[nNewitem].SubMenu[x].Text = path_parts.Filename;

also your split function needs to be inside the for loop

GoOgLe
03-24-2008, 10:51 AM
now i have 2 Addons item in the menu instead of exe files....

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
path_parts = String.SplitPath(myDocsFolder.."\\Addons", "*.exe");
name_ext=(path_parts.Filename..path_parts.Extensio n)
local x = 0;
for x = 1,Table.Count(tFiles) do
tblMenu[nNewitem].SubMenu[x] = {};
tblMenu[nNewitem].SubMenu[x].Text = path_parts.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