如何用'\'提取文件名?例如。 C:\testfolder\test.txt [英] How to extract filename with '\'? eg. c:\testfolder\test.txt

查看:147
本文介绍了如何用'\'提取文件名?例如。 C:\testfolder\test.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...


i得到了这个文件名test.txt,其位置为c:\\\ ntostfolder \ test.txt


i可以从上传对象获取完整路径名。但是我想只提取文件名。(test.txt)


i尝试使用split命令,但是当我运行javascript时它会给我错误。

错误:预期的对象。

解决方案

查看此示例代码.....


<输入type = file id = test_file_upload>


现在是js代码..............


document.getElementById(''test_file_upload'')。value。 split('''');

//尝试使用像我这样建议的拆分函数....



i hope它会工作。


亲切的问候。

dmjpro。



看看这个示例代码.....

< input type = file id = test_file_upload>



现在是js代码..............



i希望它能运作。


亲切的问候。

dmjpro。



嗨谢谢你的回复...


i已经尝试过使用split命令,当我运行时它给了我错误剧本。似乎与''\\''分裂并不起作用。我试过''\''," \",''\\''," \\"



嗨谢谢你的回复......


i已经尝试过使用split命令,当我运行脚本时它会给我错误。似乎与''\\''分裂并不起作用。我试过''\''," \",''\\''," \\"



尝试使用lastIndexOf()和子串组合。

fileName = filePath.substring(filePath.lastIndexOf(" \\\ \\"));


hi...

i got this filename test.txt with the location of c:\testfolder\test.txt

i can get the full path name from the upload object. But i want to extract only the filename.(test.txt)

i tried using the split command but it gives me error when i run the javascript.
Error: object expected.

解决方案

look at this sample code .....


<input type = file id = test_file_upload>


now the js code ..............

document.getElementById(''test_file_upload'').value. split('''');
//try to use the split function like this what i suggested....

i hope it ll work.

kind regards.
dmjpro.


look at this sample code .....


<input type = file id = test_file_upload>


now the js code ..............



i hope it ll work.

kind regards.
dmjpro.

Hi thanks for the reply...

i already tried using the split command and it gives me error when i run the script. seems like splitting with ''\'' doesnt work. i tried ''\'', "\", ''\\'', "\\"


Hi thanks for the reply...

i already tried using the split command and it gives me error when i run the script. seems like splitting with ''\'' doesnt work. i tried ''\'', "\", ''\\'', "\\"

try using lastIndexOf(), and substring in combination.
fileName = filePath.substring(filePath.lastIndexOf("\\"));


这篇关于如何用'\'提取文件名?例如。 C:\testfolder\test.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆