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. Visual Basic
  4. VBScript to split file path into 3 bits

VBScript to split file path into 3 bits

Scheduled Pinned Locked Moved Visual Basic
helptutorial
3 Posts 2 Posters 2 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.
  • M Offline
    M Offline
    mil_an
    wrote on last edited by
    #1

    Hi, I am trying to write a sub-routine in a VBScript to split a file path into 3 bits. For example I want to split the following path: "C:\Program Files\MyProg\Studio\win32\bin\filt.exe" into 3 bits: 1. C:\Program Files 2. \MyProg\Studio\win32\bin 3. \filt.exe The First part will always be de-limited by 'Program Files' (or the 2nd '\'). The Second part will be delimited from the end of 'Program Files' to the last '\' in the path. The 3rd Part will be delimited from the last '\' to the end of the path. The source of the initial file path is stored in an input file, and the split path is to be stored in another text file in the following format: "C:\Program Files" ** "\MyProg\Studio\win32\bin" ** "\filt.exe" I hope this is clear, and someone will be able to assist. Any help will be much appreciated. Thanks :)

    D 1 Reply Last reply
    0
    • M mil_an

      Hi, I am trying to write a sub-routine in a VBScript to split a file path into 3 bits. For example I want to split the following path: "C:\Program Files\MyProg\Studio\win32\bin\filt.exe" into 3 bits: 1. C:\Program Files 2. \MyProg\Studio\win32\bin 3. \filt.exe The First part will always be de-limited by 'Program Files' (or the 2nd '\'). The Second part will be delimited from the end of 'Program Files' to the last '\' in the path. The 3rd Part will be delimited from the last '\' to the end of the path. The source of the initial file path is stored in an input file, and the split path is to be stored in another text file in the following format: "C:\Program Files" ** "\MyProg\Studio\win32\bin" ** "\filt.exe" I hope this is clear, and someone will be able to assist. Any help will be much appreciated. Thanks :)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This is simple string handling. You can use the FileSystemObject's GetFilename method to get the last part of the string. You can use WScript.ExpandEnvironmentStrings to get the path to the Program Files folder (which is NOT always on C:!!). All you need to do is exand the environment variable "ProgramFiles" and it'll usually return C:\Program Files. After that, it's simple string handling to get the middle part. Hint: What's the length of the strings returned by both of these calls? Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 14:34 Monday 26th June, 2006

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This is simple string handling. You can use the FileSystemObject's GetFilename method to get the last part of the string. You can use WScript.ExpandEnvironmentStrings to get the path to the Program Files folder (which is NOT always on C:!!). All you need to do is exand the environment variable "ProgramFiles" and it'll usually return C:\Program Files. After that, it's simple string handling to get the middle part. Hint: What's the length of the strings returned by both of these calls? Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 14:34 Monday 26th June, 2006

        M Offline
        M Offline
        mil_an
        wrote on last edited by
        #3

        Thanks Dave :-D

        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