Re: ?? Converting CurrentDirectory to a String ?? by Paul
Paul
Sun Apr 27 10:39:35 CDT 2008
"Tom Baxter" <tlbaxter99@newsgroup.nospam> wrote in message
news:O4wh6iDqIHA.1736@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> I have a snippet of code like this:
>
> fso.CreateTextFile(WScript.Shell.CurrentDirectory & "\blah" &
> ".xyz")
>
> I want to convert the thing in parentheses to a string. I want to do
> something like this:
>
> Dim somePath
> somePath = WScript.Shell.CurrentDirectory & "\blah" & ".xyz"
>
> But this doesn't work. I've tried using CStr() but that doesn't work
> either.
>
> Is there a way to make the darned thing a string?
Hi Tom,
First, you have to determine what you mean by 'current directory'.
WScript.Shell.CurrentDirectory will give you a different opinion on
what the current directory is depending on how you invoke the script.
For example, you can run the following script by 1) dragging a file to
it in an explorer window, or 2) you can double click it in an explorer
window.
'Demonstrates a different CurrentDirectory depending on
'started by double clicking or dragging a file to the script.
Option Explicit
Dim i, objArgs, sMsg
sMsg = "WScript.Arguments = "
MsgBox "started in " & vbCrLf & _
WScript.CreateObject("WScript.Shell").CurrentDirectory
Set objArgs = WScript.Arguments
For i = 0 to objArgs.Count - 1
sMsg = sMsg & vbCrLf & objArgs(I)
Next
MsgBox "Done" & vbCrLf & sMsg
For current directory, I usually mean the folder in which the script
resides, so I use the following to force the current directory to be
that path:
objShell.CurrentDirectory = _
objFSO.GetParentFolderName(WScript.ScriptFullName)
-Paul Randall