+ Reply to Thread
Results 1 to 2 of 2

Extracting the folder name and filename from a file path?

  1. #1
    Registered User
    Join Date
    03-26-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Extracting the folder name and filename from a file path?

    How would one extract a filename or a folder name from the path to a a file?

    For instance, given a Windows path like:

    C:\SomeFolder\SubFolderA\SubFolderB\filename.txt.bak

    Or a Unix path like:
    \SomeFolder\SubFolderA\SubFolderB\filename.txt.bak

    The function =foldername(...) would return "SomeFolder\SubFolderA\SubFolderB" and =filename(...) would return "filename.txt.bak".

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,725

    Re: Extracting the folder name and filename from a file path?

    The algorithm is quite straightforward, as the filename is always at the right-hand end of the string. So, starting from that end, examine each character in turn (and count the number of characters) until you reach a \ or : The filename can be obtained using RIGHT and the path can be obtained using LEFT, along with the count of characters and the original length of the string.

    Hope this helps.

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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