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?
--
Tom Baxter

Re: ?? Converting CurrentDirectory to a String ?? by Pegasus

Pegasus
Sun Apr 27 02:40:28 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?
> --
> Tom Baxter

There is no need to bring the WScript.Shell object into the game -
the FSO object will suffice:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFldr = objFSO.GetFolder(".")
WD = objFSO.GetAbsolutePathName(ObjFldr)



Re: ?? Converting CurrentDirectory to a String ?? by mayayana

mayayana
Sun Apr 27 08:48:31 CDT 2008

If you want to do that you have to create the WScript.Shell
object first:

Set SH = CreateObject("WScript.Shell")
sPath = SH.CurrentDirectory

Are you sure that's actually what you want? CurrentDirectory
typically returns C drive and I don't think there's even a
"change directory" command available in VBScript. It's a DOS
leftover.

If what you really want is the script's path you
can do it like this:

Dim sPath, Pt1
sPath = WScript.ScriptFullName
Pt1 = InStrRev(sPath, "\")
sPath = Left(sPath, Pt1)
'-- That returns the parent folder path.
'-- Then you add your new file name.
sPath = sPath & "blah.xyz"

>
> 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?
> --
> Tom Baxter
>
>
>
>



Re: ?? Converting CurrentDirectory to a String ?? by Alex

Alex
Sun Apr 27 09:44:58 CDT 2008

"mayayana" <mayaXXyana1a@mindXXspring.com> wrote in message
news:OMBzZ1GqIHA.672@TK2MSFTNGP02.phx.gbl...
> If you want to do that you have to create the WScript.Shell
> object first:
>
> Set SH = CreateObject("WScript.Shell")
> sPath = SH.CurrentDirectory
>
> Are you sure that's actually what you want? CurrentDirectory
> typically returns C drive and I don't think there's even a
> "change directory" command available in VBScript. It's a DOS
> leftover.

Actually, what you just showed really is what he wants (Pegasus' method is
less common but more elegant I think because when you're worried about file
naming, you're going to want other facilities available in FSO anyway). This
is useful for various "local" operations that are more closely related to
system maintenance or managing projects with lots of files.

You really can control the directory with this - CurrentDirectory is a
settable property. What it shows is the process working directory path,
which also means when you're doing file operations relative to this path you
can simplify how you name them or expand them.

> If what you really want is the script's path you
> can do it like this:
>
> Dim sPath, Pt1
> sPath = WScript.ScriptFullName
> Pt1 = InStrRev(sPath, "\")
> sPath = Left(sPath, Pt1)
> '-- That returns the parent folder path.
> '-- Then you add your new file name.
> sPath = sPath & "blah.xyz"
>
>>
>> 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?
>> --
>> Tom Baxter
>>
>>
>>
>>
>
>

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



Re: ?? Converting CurrentDirectory to a String ?? by Tom

Tom
Sun Apr 27 14:48:06 CDT 2008

Thank you all. Your posts were helpful. From the various posts I was able to
piece together what I needed. Thanks again.

--
Tom Baxter



"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?
> --
> Tom Baxter
>
>
>
>



Re: ?? Converting CurrentDirectory to a String ?? by Dusty

Dusty
Mon Apr 28 14:43:18 CDT 2008

Try this...

Dim somePath
Set objShell = WScript.CreateObject("WScript.Shell")
somepath = objShell.CurrentDirectory
msgbox (" You are Currently in " & somepath)



Cheers,
Dusty
"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?
> --
> Tom Baxter
>
>
>
>

Re: ?? Converting CurrentDirectory to a String ?? by James

James
Tue Apr 29 16:01:50 CDT 2008

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:uK6L6nDqIHA.1436@TK2MSFTNGP05.phx.gbl...
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set ObjFldr = objFSO.GetFolder(".")
> WD = objFSO.GetAbsolutePathName(ObjFldr)

Interesting tip. Thanks!

I have always parsed the output of 'WScript.ScriptFullName' or
'oWSH.CurrentDirectory'. It is always nice to learn new methods! I was
completely unaware of the method you used above.