Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  171] [ 6]  / answers: 1 / hits: 57870  / 15 Years ago, mon, may 4, 2009, 12:00:00

How to get the directory of a file?



For example, I pass in a string



C:Program Filesnantbinnant.exe


I want a function that returns me



C:Program Filesnantbin


I would prefer a built in function that does the job, instead of having manually split the string and exclude the last one.



Edit: I am running on Windows


More From » javascript

 Answers
87

I don't know if there is any built in functionality for this, but it's pretty straight forward to get the path.



path = path.substring(0,path.lastIndexOf(\)+1);

[#99603] Wednesday, April 29, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffery

Total Points: 180
Total Questions: 114
Total Answers: 117

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;