Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:splitpath [2015/09/14] (current)
Line 1: Line 1:
 +======Splitting a File Path String======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //How to break a file path string in to its components.//​
 +
 +=====Overview=====
 +When writing C/C++ applications,​ the C-runtime library provides the **_splitpath** function to break a path string into its four component pieces. It is possible to write a similar function in VBScript with some help from scripting'​s [[developer:​filesystemobject|FileSystemObject]].
 +
 +=====Example =====
 +
 +The following VBScript subroutine can be used to break a file path string into its components.
 +
 +<code vb>
 + Sub SplitPath(ByVal sPath, ByRef sDrive, ByRef sDir, ByRef sFname, ByRef sExt)
 +   Dim fso
 +   Set fso = CreateObject("​Scripting.FileSystemObject"​)
 +   ​sDrive = fso.GetDriveName(sPath)
 +   sDir = Mid(fso.GetParentFolderName(sPath),​ Len(sDrive)+1) & "​\"​
 +   ​sFname = fso.GetBaseName(sPath)
 +   sExt = "​."​ & fso.GetExtensionName(sPath)
 +   Set fso = Nothing
 + End Sub
 +</​code>​
 +
 +The subroutine can be used as follows:
 +
 +<code vb>
 + Sub Test()
 +   Dim sPath, sDrive, sDir, sFname, sExt
 +   sPath = Rhino.DocumentPath & Rhino.DocumentName
 +   ​SplitPath sPath, sDrive, sDir, sFname, sExt
 +   ​MsgBox sDrive & VbCrLf & sDir & VbCrLf & sFname & VbCrLf & sExt
 + End Sub
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/splitpath.txt ยท Last modified: 2015/09/14 (external edit)