Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel formula (not VBA) to calculate basename of a file path?

Is it possible to determine the basename, i.e. the last path component of a file path in Excel without defining a custom VBA function?

For example, if cell A1 has the value

C:\Some\deep\directory\structure\file.txt

the formula in B1 should use A1 to return

file.txt

Any ideas?

like image 622
Karsten W. Avatar asked May 12 '12 09:05

Karsten W.


People also ask

How do I extract filenames?

To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null.

How do I change the file path in Excel?

Under the "Data" Tab, click "Edit Links" - this should show you the files you have linked to, and you can "Change Source" to update it. Alternatively, you could do a simple Find/Replace (CTRL+F, then click "replace" and type the path you need to replace and then in the replace area, put the new path).


1 Answers

=RIGHT(A1,LEN(A1)-FIND("|",SUBSTITUTE(A1,"\","|",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
like image 79
assylias Avatar answered Nov 02 '22 23:11

assylias