469,613 Members | 1,646 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

JavaScript code to get FileName from File Inputbox

Alright, I'm very new to JavaScript but I'm fair with PHP.
I'm working on an uploader script and what I'm trying to do is take the file name from the file input box.

I looked at string manipulation in terms of using indexOf, substr, substring, etc... and I can't figure it out for the life of me!

Here is what I'm trying to do:

Example:
I select the file:
C:\Documents and Settings\BSPROGS\Desktop\DeVry\Previous work\BIS 440\ESSS_Case_Study.zip

I want to use the document.write command to write:
ESSS_Case_Study.zip

I've looked through my "javascript: The Definitive Guide" book from O'Reilly but luck.

Thanks for your help.

Steven
Jan 15 '07 #1
2 3783
First, you split the string into string array using '\' and get its array length. Then get the penultimate string value.... Hope it works....Find below the example code..

var strPath = C:\Documents and Settings\BSPROGS\Desktop\DeVry\Previous work\BIS 440\ESSS_Case_Study.zip
var strPathArray = strPath.split('\');
var strFileName = strPathArray[strPathArray.length-1];

You can get the name in strFileName variable....
Jan 15 '07 #2
First, you split the string into string array using '\' and get its array length. Then get the penultimate string value.... Hope it works....Find below the example code..

var strPath = C:\Documents and Settings\BSPROGS\Desktop\DeVry\Previous work\BIS 440\ESSS_Case_Study.zip
var strPathArray = strPath.split('\');
var strFileName = strPathArray[strPathArray.length-1];

You can get the name in strFileName variable....
That worked perfectly! Thank you. :)
As I learn more of how the JavaScript functions work, I'll get the hang of it, haha.
Jan 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by NewUser | last post: by
5 posts views Thread by mgershma | last post: by
8 posts views Thread by chrisdude911 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.