PDA

View Full Version : Find Parent Folder From Given Folder / File Path



Excel Fox
05-28-2011, 03:17 PM
This will give the path of the parent folder. The advantage of this formula is that you can pass the hierarchy level by just changing the last argument in the formula (highlighted in bold red)

Array Formula (confirmed by pressing CTRL+SHIFT+ENTER, this formula is otherwise known as CSE formula)
=LEFT(A1,LARGE((MID(A1,ROW(1:255),1)="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),1))


Example
I:\Pictures\Wallpapers\World Over\Misc Pics\New Delhi.jpg
the above formula will give
I:\Pictures\Wallpapers\World Over\Misc Pics\

Changing the argument to 2

I:\Pictures\Wallpapers\World Over\
3
I:\Pictures\Wallpapers\

so on and so forth.....:)

Excel Fox
05-28-2011, 03:50 PM
Add to extract just the folder name

=MID(A1,LARGE((MID(A1,ROW(1:255),1)="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),2)+1,LARGE((MID(A1,ROW(1:255),1 )="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),1)-LARGE((MID(A1,ROW(1:255),1)="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),2)-1) and this will give

Misc Pics

=MID(A1,LARGE((MID(A1,ROW(1:255),1)="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),3)+1,LARGE((MID(A1,ROW(1:255),1 )="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),2)-LARGE((MID(A1,ROW(1:255),1)="\")*IFERROR(SEARCH("\",A1,ROW(1:255)),0),3)-1)

World Over