473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to get basename of a file name?

Is there an equivalent to a "basename" in javascript
that returns the last part of a file name?
For example, given "C:\My Documents\test.txt" and
"/usr/local/test.txt", both should return "test.txt".
Any help would be appreciated.
Jul 23 '05 #1
1 11002
Ivo
"Wild Pete" wrote
Is there an equivalent to a "basename" in javascript
that returns the last part of a file name?
For example, given "C:\My Documents\test.txt" and
"/usr/local/test.txt", both should return "test.txt".


Backslashes in strings should be escaped with another backslash, so
use "C:\\My Documents\\test.txt" instead. Then run this regex:

var a="/usr/local/test.txt";
var b=a.match(/[\/|\\]([^\\\/]+)$/);
alert( b[1] );

--Iv


Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: praba kar | last post by:
Dear All, I am using Python 2.4 in the linux platform. At present I am working on webbased file manager. When I try to upload a file from the linux cgi script easily fetch the file name by the...
21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
3
by: Wayne Aprato | last post by:
I am using code kindly provided by the Access Web to capture a file path and insert it into a form. The relevant part of the code follows: Function GetOpenFile(Optional varDirectory As Variant,...
39
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
4
by: carmelo | last post by:
Hi! I need to read and store data from a file, but I don't the name of it; Is this code correct and is there a better way to do this thing?? int main() { cout << " type file name:" char *...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.