Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <a href="http://msdn.microsoft.com/en-us/library/bb773748(VS.85).aspx" rel="nofollow noreferrer">PathRemoveFileSpec</a> function, available in every version of Windows from 2000 and 98. Here is a VB6 implementation. </p> <pre><code>Private Declare Function PathRemoveFileSpec Lib "Shlwapi" _ Alias "PathRemoveFileSpecW" (ByVal szPath As Long) As Long 'Convert input file path to drive &amp; directory only. (Supports UNC too) ' Function sPathOnly(ByVal sInput As String) As String Dim sWorking As String sWorking = sInput If (PathRemoveFileSpec(StrPtr(sWorking)) &lt;&gt; 0) Then 'Call succeeded. Trim trailing Null ' sPathOnly = sTrimNull(sWorking) Else sPathOnly = sWorking End If End Function 'Trim trailing null characters (e.g. from a string returned from an API call) ' Function sTrimNull(ByVal sIn As String) As String Dim iZeroCharacter As Long iZeroCharacter = InStr(sIn, Chr$(0)) If iZeroCharacter &gt; 0 Then sTrimNull = Left$(sIn, iZeroCharacter - 1) Else sTrimNull = sIn End If End Function </code></pre> <p>I prefer to avoid the Microsoft Scripting Runtime (including FileSystemObject). In my experience it's occasionally broken on user machines, perhaps because their IT department are paranoid about viruses. There are <a href="http://msdn.microsoft.com/en-us/library/aa155716%28office.10%29.aspx" rel="nofollow noreferrer">other useful functions</a> in shlwapi.dll, e.g. for testing whether <a href="https://stackoverflow.com/questions/1135614/how-to-find-if-the-network-path-is-available-or-not/1136408#1136408">folders exist</a> or <a href="http://msdn.microsoft.com/en-us/library/bb773584(VS.85).aspx" rel="nofollow noreferrer">files exist</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload