Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Current Directory w/o ASP 1

Status
Not open for further replies.

donmc4

Programmer
Jun 27, 2003
11
0
0
CA
Is it possible to get the current drive and directory information similar to CurrentProject.Path in VBA.
 
Try this:
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo WshShell.CurrentDirectory

Hope This Help
PH.
 
Thanks for your reply.

I tried it and I get error message "Object required 'WScript'". Any ideas?
 
Try this:
Code:
Set WshShell = CreateObject("WScript.Shell")
WScript.Echo WshShell.CurrentDirectory


Hope This Help
PH.
 
What's your script host? Is this IE client-side script?

If so, try window.location.pathname but you'll probably need to URL-decode it. URL decoding is easier using a JScript helper function you can call from VBScript that invokes the decodeURIComponent() method.
Code:
<script language=&quot;JScript&quot;>
function URLDecode(s)
{
  return(decodeURIComponent(s))
}
</script>
<script>
Function GetPath()
  'Get file path to current
  'file-based web page.
  Dim s, fol

  s = URLDecode(window.location.pathname)

  'We want to back up to our folder.
  fol = InStrRev(s, &quot;\&quot;)

  'Under some conditions we have a leading &quot;/&quot;
  If Left(s, 1) = &quot;/&quot; Then
    GetPath = Mid(s, 2, fol - 1)
  Else
    GetPath = Left(s, fol)
  End If
End Function
</script>
This is most commonly used in HTAs, but can be used for file-based webs too.
 
Oops!

The second <script> tag should specify language=&quot;VBScript&quot; - sorry.
 
Thanks 'dilettante' it seemed to work with no URL decoder required.

Don
 
You'll be fine until you encounter a directory name with a space in it ;-)
 
I just used the Replace command to replace &quot;%20&quot; with &quot; &quot;. It seemed to work fine. What do you think?

Thanks
Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top