對於一個帶絕對路徑的文件名如
首先為了避免轉義反斜槓出問題
D:#Program Files#Notepad++#Notepad++
之後以‘#
D: ProgramFiles Notepad++ Notepad++
取數組的最後一個即為帶後綴的文件名
再以‘
Notepad++ exe
然後再取數組的最後一個就可以得到文件的後綴名exe了
代碼如下(Win
//by MoreWindows
function GetExtensionFileName(pathfilename)
{
var reg = /(+)/g;
var pfn = pathfilename
var arrpfn = pfn
var fn = arrpfn[arrpfn
var arrfn = fn
return arrfn[arrfn
}
//by MoreWindows
function GetExtensionFileName(pathfilename)
{
var reg = /(+)/g;
var pfn = pathfilename
var arrpfn = pfn
var fn = arrpfn[arrpfn
var arrfn = fn
return arrfn[arrfn
}
測試代碼
function Test()
{
var filePath="D:Program FilesNotepad++Notepad++
alert(GetExtensionFileName(filePath));
}
<input type="button" value="Test" onclick="Test()" />
function Test()
{
var filePath="D:Program FilesNotepad++Notepad++
alert(GetExtensionFileName(filePath));
}
<input type="button" value="Test" onclick="Test()" />
點擊Test按鈕就可以彈出內容為exe的對話框
估計這種方法只能在Windows平台下使用吧
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20013.html