Get Folder Name

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I know how to get the file path...

=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

But is there a way to get just the FOLDER name (not the entire path) of the current file?

DJ
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:
Code:
=TRIM(LEFT(SUBSTITUTE(RIGHT(SUBSTITUTE(SUBSTITUTE( LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),"[",""),"\",REPT(" ",30)),60),REPT(" ",30),"\"),FIND("\",SUBSTITUTE(RIGHT(SUBSTITUTE(SUBSTITUTE( LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),"[",""),"\",REPT(" ",30)),60),REPT(" ",30),"\"))-1))
 
Upvote 0
Thanks for the quick reply. I think you are on the right track....

It doesn't bring back enough characters, though. I'm only getting the last 12 characters between the backslashes.

DJ
 
Upvote 0
Try this in A1 (Save file after entered formula)
Code:
=IFERROR(TRIM(SUBSTITUTE(MID(LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1),FIND(CHAR(1),SUBSTITUTE(LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1),"\",CHAR(1),(LEN(LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1))-LEN(SUBSTITUTE(LOWER(LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)),"\","")))/1-1))+1,20),"\","")),"")
 
Upvote 0
Okay, that got me the first 20 characters between the last two backslashes.

I want everything between those two backslashes. And the number of characters will vary, of course.

DJ
 
Upvote 0
The first 20 or the last 20? Should give you more than that.

Give me a real filepath to work with.
 
Upvote 0
C:\Users\DJLTC\Box Sync\DJLTC\01 - Courses\EXC10\DJL Training EXC10 Student Files (XLSM)\Level 1\Lesson 02 - Editing, Viewing, and Printing Worksheets\
 
Upvote 0
Correct. The formula I posted gets the file path. I just want the end of the path, the last folder.

DJ
 
Upvote 0
Get Folder Name only from pathe

Correct. The formula I posted gets the file path. I just want the end of the path, the last folder.
What is problem with my formula
See this ss
example.png


Just change this part of formula
/1-1))+1;20)

to

/1-1))+1;100)

[EDIT] Sorry, on the screenshot formula need to be in A7 cell
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,738
Members
449,116
Latest member
alexlomt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top