PDA

View Full Version : how to get file extension


paul186
12-27-2008, 07:08 AM
hi to all again,
i wonder if anyone can help me, i wassearching in teh forums but found nothing about that and i think its a easy thing but i dont know hoe to do...
i explain: i want that when the user press a button load a mp3 or a vid, but for this i need to get the file.extension, wich i dont know how to do...

now my code is: (but its wrong...)

file_path = Dialog.FileBrowse(true, "Abrir archivo..", _DesktopFolder, "Video Files (.avi, .mpg, .mpeg, .wmv, .asf, )|*.avi;*.mpg;*.mpeg;*.wmv;*.asf|All Files (*.*)|*.*|", "", "", false, true);
--get file extension? i dont know how to do it...
file = String.SplitPath(file_path);
if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
if file.extension == ".avi" or ".MPG" then
--do whatelse
else if file.extension == ".mp3" then
--doanother thing
end
end
end


thanks for all

Imagine Programming
12-27-2008, 07:51 AM
Something like this should do:

file_path = Dialog.FileBrowse(true, "Abrir archivo..", _DesktopFolder, "Video Files (.avi, .mpg, .mpeg, .wmv, .asf, )|*.avi;*.mpg;*.mpeg;*.wmv;*.asf|All Files (*.*)|*.*|", "", "", false, true);
if(file_path[1]~="CANCEL")then
if(File.DoesExist(file_path[1]))then
local extension=String.Lower(String.SplitPath(file_path[1]).Extension)
if(extension==".avi")or(extension=="mpg")then
--Actions for avi
elseif(extension==".mp3")then --Remember do type the extensions (only in this if statement) in lower case, because we are using String.Lower while we get the extension
--Actions for mpg
end
end

paul186
12-27-2008, 07:53 AM
lol what a fast reply! THANKS mate :yes