views:

125

answers:

2

Hello

How do I determine if a path is relative or absolute in Visual Basic Script.

In VBA, I'd call the Win32 Api function PathIsRelative

Private Declare Function PathIsRelative Lib "shlwapi" _
    Alias "PathIsRelativeA" _
   (ByVal pszPath As String) As Long

However, it's not possible to call into a DLL from VBS, so I cannot use the Win32 Api.

René

A: 
dim position
position = InStr("your-path", ":")

If position > 0 Then
  ''# absolute path
else
  ''# relative path
end if
Sarfraz
I should point out that the ; and // are both java/c/c++/etc like.
René Nyffenegger
Checking for a presence of a colon isn't enough. For example, `C:\file.txt` is a full path whereas `C:file.txt` is relative (see http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#fully_qualified_vs._relative_paths).
Helen
@Helen: great info, thanks but can't figure out where this path relates to?
Sarfraz
`C:file.txt` refers to the `file.txt` file in the current folder on drive `C`. Similarly, `C:folder\file.txt` refers to a file in the `folder` subfolder of the current folder; `C:..\file.txt` -- to a file in the parent folder of the current folder, and so on.
Helen
@Helen: hmm, useful info, thanks
Sarfraz
A: 
set oFSO = CREATEOBJECT("Scripting.FileSystemObject")

relativePath = ""
absolutePath = "c:\test"

MsgBox UCase(relativePath) = UCase(oFSO.GetAbsolutePathName(relativePath))
MsgBox UCase(absolutePath) = UCase(oFSO.GetAbsolutePathName(absolutePath))
Tom Brothers