how to get working drive and directory?

Author Message
LawfulEvil
  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 7/25/2004
  • Location:
how to get working drive and directory? - Sunday, August 15, 2004 5:47 PM
0
Dear all,

I need to write a script to read the script's directory information and i face some problem.

if i put my script under C:\temp

How can i get the working drive (return c:\) ?
How can i get the working directory? (return temp or c:\temp)?


LawfulEvil
  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 7/25/2004
  • Location:
Re: how to get working drive and directory? - Sunday, August 15, 2004 8:56 PM
0
ops.

I get it solve


Set fso = CreateObject("Scripting.FileSystemObject")
filepath = fso.GetAbsolutePathName("")

mbouchard
  • Total Posts : 2186
  • Scores: 37
  • Reward points : 0
  • Joined: 5/15/2003
  • Location: USA
Re: how to get working drive and directory? - Monday, August 16, 2004 1:36 AM
0
Here are a couple other ways to get the info you are looking for.

Set fso = CreateObject("Scripting.FileSystemObject")
GetAbsolutePath = fso.GetAbsolutePathName("Wscript.ScriptName") 'Returns path and file name of file specified
GetTheParent = fso.GetParentFolderName("Wscript.ScriptName")'Returns the parentfolder of the Path/File specified
GetTheBase = fso.GetBaseName("Wscript.ScriptName")'Returns the file name minus file extension
GetTheScriptFullName = WScript.ScriptFullName'Returns path of the script being called.
GetTheScriptName = Wscript.ScriptName'Returns the name of the script

msgbox "Using AbsolutePath: " & GetAbsolutePath & vbcr _
& "Using GetParentFolderName: " & GetTheParent & vbcr _
& "Using GetBaseName: " & GetTheBase & vbcr _
& "Using ScriptFullName: " & GetTheScriptFullName & vbcr _
& "Using ScriptName: " & GetTheScriptName

LawfulEvil
  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 7/25/2004
  • Location:
Re: how to get working drive and directory? - Tuesday, August 17, 2004 7:07 PM
0
thanks mbouchard.

your detail reply is very useful for me.
Thank you

flapclock
  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 9/5/2004
  • Location:
Re: how to get working drive and directory? - Sunday, September 05, 2004 8:45 PM
0
mbouchard's answer is actually very incorrect. LawfulEvil, use this instead:

Set fso = CreateObject("Scripting.FileSystemObject")
GetDriveName = fso.getDriveName(WScript.ScriptFullName)'Returns the drive
GetParentFolderName = fso.GetParentFolderName(WScript.ScriptFullName)'Returns the parentfolder of the Path/File specified
GetBaseName = fso.GetBaseName(WScript.ScriptName)'Returns the file name minus file extension
GetScriptFullName = WScript.ScriptFullName 'Returns path and file name of file specified
GetScriptName = Wscript.ScriptName'Returns the name of the script

MsgBox "Using GetDriveName: " & GetDriveName & vbCr _
& "Using GetParentFolderName: " & GetParentFolderName & vbCr _
& "Using GetBaseName: " & GetBaseName & vbCr _
& "Using GetFullName: " & GetScriptFullName & vbCr _
& "Using ScriptName: " & GetScriptName

I removed "GetAbsolutePath" because it's exactly the same as getting the full name of the script, and added getdrivename, as you wanted to know the drive your script was executing in.

mbouchard
  • Total Posts : 2186
  • Scores: 37
  • Reward points : 0
  • Joined: 5/15/2003
  • Location: USA
Re: how to get working drive and directory? - Tuesday, September 07, 2004 1:40 AM
0
Flaplock, What is "very incorrect" about my post? Just wondering.