+ Reply to Thread
Results 1 to 20 of 20

Separate complete path to file and directory path

  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Separate complete path to file and directory path

    col. a: c:\1\2\3\file.txt

    desired result
    col. b: file.txt
    col. c: c:\1\2\3


    of course the number of subdirectories varies as well as the string length of any directory / subdirectory.
    the extension is always a 3 letter extension in this case, BUT to make it compatible allow for more (like .docx etc)

    Thanks

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    If data are in A1.

    b1
    =TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",50)),50))

    c1
    SUBSTITUTE(A1,C1,"")
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    If you don't want the last /....

    =LEFT(SUBSTITUTE(A1,C1,""),LEN(SUBSTITUTE(A1,C1,""))-1) in C1

  4. #4
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,367

    Re: Separate complete path to file and directory path

    Maybe like this, consider the text on A1, put this on B1
    =LEFT(A1,LOOKUP(2^15,FIND("\"," "&A1,ROW(INDIRECT("1:"&LEN(A1)))))-1)

    and this one on C1
    =TRIM(RIGHT(SUBSTITUTE(TRIM(A1),"\",REPT(" ",255)),255))

  5. #5
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    @Glenn
    Did it again! Just substitute c with b in the formulas (Can't refer to c in a formula residing in c).

    @azumi
    Good to have alternatives! Just correct, the first in c and the second in b.

    Thank you both!

  6. #6
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    @Glen

    Your solution assumes that no file name + ext exceeds 50 characters, right?

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,719

    Re: Separate complete path to file and directory path

    Quote Originally Posted by drgkt View Post
    @Glen

    Your solution assumes that no file name + ext exceeds 50 characters, right?
    If your strings exceed that, try increasing the number - does that then work for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    Yes, so far.
    Can a formula find the longest file name in the range? (Then I will adjust the number accordingly ).
    Last edited by drgkt; 10-27-2016 at 12:11 PM.

  9. #9
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    No way to find longest file name in range? (Count characters after last occurence of "\")?

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    =len(A1) will return the no. of characters in A1

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,719

    Re: Separate complete path to file and directory path

    Just choose a really high number for the formula.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    the length of the bit before the last / is largely irrelevant. If the bit after the last / can be more than 50 characters, increase the 50 to, for example:

    =TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",100)),100))

    one of the benefits of being a professional scientist: I know the power of experimentation. try it out & see what happens. If it doesn't explode, it can't be too far wrong....
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    If it doesn't explode.... xaxaxaxa

    Yes Glenn I agree

    I just wonder if there is a way to find the maximum file name string length (say in range a1:a100). That would be the number of characters after the last occurrence of "\" in each cell (filename plus period plus extension).

    But how to translate that in a formula?

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Separate complete path to file and directory path

    Try array entering this. If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    Instead of 100 you can use LEN(A1) in the formulae... which will work providing that the number of characters in the cell (n) plus x.n (where x= number of / in the string) is less than 32767.

  16. #16
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    Quote Originally Posted by Glenn Kennedy View Post
    Instead of 100 you can use LEN(A1) in the formulae... which will work providing that the number of characters in the cell (n) plus x.n (where x= number of / in the string) is less than 32767.
    Is this an excel formula limit? I mean how is it derived?

  17. #17
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    A cell can contain no more than 32767 characters (in Excel 2010)

  18. #18
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Separate complete path to file and directory path

    ok. So max.n=32767, granted.

    What is the need for n+x.n like you mentioned above?

  19. #19
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,006

    Re: Separate complete path to file and directory path

    That was me trying to explain (badly) what was happening. You have Excel 2002, I don't know the max number of characters you can have, but it will be fewer (much fewer) than 32767.

  20. #20
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Separate complete path to file and directory path

    According to this

    http://excel.tips.net/T003163_Charac...for_Cells.html

    it's 1,024. Which means my formula won't work in Excel 2002 / 2003. Oversight on my part. My apologies.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Provide Complete Path of File List
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2015, 09:25 AM
  2. How to validate an input dat folder/directory path whether the path has any spaces
    By mahendra.asapu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2015, 02:39 AM
  3. Change directory to specified file path
    By Adventuyre_Harry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2013, 06:42 AM
  4. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  5. Return full file path for files in directory
    By jeffreybrown in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-03-2011, 12:42 PM
  6. File path of DIrectory and Folders only
    By teachMeExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2009, 11:02 PM
  7. How do I insert the directory path in my Excel file?
    By Insert a Directory Path in Hea in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-04-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1