Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I extract drive name from file path?

How do I extract drive name from file path?

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadmin
3 Posts 3 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.

    A C 2 Replies Last reply
    0
    • L Lost User

      I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.

      A Offline
      A Offline
      Al
      wrote on last edited by
      #2

      I use something like the following to get the path of an executing application: CString sPath; // get the path where the application is running GetModuleFileName(AfxGetApp()->m_hInstance, sPath.GetBuffer(_MAX_PATH+1),_MAX_PATH); //path+file sPath.ReleaseBuffer(); // releases excess memory sPath = sPath.Left(sPath.ReverseFind('\\')); //keep path ReverseFind finds the zero-based index of the first matching character (from the end). You could use the equivalent of sPath.find and look for the first ":" or ":\" character (without the quotes naturally). Hope this helps. Al ================== The original message was: I've got a set of filenames: some are to files which exist, others are to files which do not exist;
      some are absolute, others are relative; some are on local drives, others on network drives.

      I'm looking for a way to extract the drive name from a file path, regardless of any of the above
      factors.

      Can anyone give me a pointer of where to look for this?

      Thanx.

      1 Reply Last reply
      0
      • L Lost User

        I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.

        C Offline
        C Offline
        Chris Scott
        wrote on last edited by
        #3

        Have a look at the _splitpath API function... - Chris ================== The original message was: I've got a set of filenames: some are to files which exist, others are to files which do not exist;
        some are absolute, others are relative; some are on local drives, others on network drives.

        I'm looking for a way to extract the drive name from a file path, regardless of any of the above
        factors.

        Can anyone give me a pointer of where to look for this?

        Thanx.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups