VBScript to split file path into 3 bits
-
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 :)
-
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 :)
This is simple string handling. You can use the
FileSystemObject
'sGetFilename
method to get the last part of the string. You can useWScript.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 returnC:\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 -
This is simple string handling. You can use the
FileSystemObject
'sGetFilename
method to get the last part of the string. You can useWScript.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 returnC:\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