I've got a VBScript that has a section which creates a temporary file:

Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Const TemporaryFolder = 2
Set tempFolder = FSO.GetSpecialFolder(TemporaryFolder)
logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
Set logFile = FSO.CreateTextFile(logFname, True)
logFile.Close

This appears to work on NT, Windows XP, Windows 2000, Windows 2003...
except in a few cases where we've seen the value returned from
ShortPath
still has embedded spaces, e.g.

C:\DOCUME~1\<username>\Local Settings\Temp\2

Is this a known issue? Any workaround or suggestions on how to
correct this?

RE: GetSpecialFolder(2).ShortPath not always returning fully-shortened by urkec

urkec
Thu May 17 16:20:00 CDT 2007

"VogonP@gmail.com" wrote:

> I've got a VBScript that has a section which creates a temporary file:
>
> Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
> Const TemporaryFolder = 2
> Set tempFolder = FSO.GetSpecialFolder(TemporaryFolder)
> logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
> Set logFile = FSO.CreateTextFile(logFname, True)
> logFile.Close
>
> This appears to work on NT, Windows XP, Windows 2000, Windows 2003...
> except in a few cases where we've seen the value returned from
> ShortPath
> still has embedded spaces, e.g.
>
> C:\DOCUME~1\<username>\Local Settings\Temp\2
>
> Is this a known issue? Any workaround or suggestions on how to
> correct this?
>
>


What happens when there are spaces in the path?

--
urkec



Re: GetSpecialFolder(2).ShortPath not always returning fully-shortened path? by D

D
Thu May 17 17:26:27 CDT 2007

Hi VogonP,

I use the following, and I've not had a problem with it yet:

Const ci_temporary_folder = 2
Const cs_script_version = "v0.13"
Const cs_bs = "\"

Dim go_fso
Dim gs_script_spec, gs_script_path, gs_script_name, gs_script_title,
gs_script_fac
Dim gs_temp_file, gs_temp_path, gs_temp_spec

Set go_fso = CreateObject( "Scripting.FileSystemObject" )

gs_script_spec = Wscript.ScriptFullName
gs_script_path = go_fso.GetParentFolderName( gs_script_spec )
gs_script_name = go_fso.GetBaseName( gs_script_spec )
gs_script_title = gs_script_name & " (" & cs_script_version & ")"
gs_script_fac = "%" & gs_script_name & ", "

gs_temp_file = go_fso.GetTempName
gs_temp_path = go_fso.GetSpecialFolder( ci_temporary_folder )
gs_temp_spec = gs_temp_path & cs_bs & gs_temp_file


...i.e. I don't use the .BuildPath method, I just concatenate the two
strings. Sometimes I use "gs_script_path" other times "gs_temp_path".

HTH,
Regards,
Dave.



<VogonP@gmail.com> wrote in message
news:1179434955.331469.41360@q23g2000hsg.googlegroups.com...
> I've got a VBScript that has a section which creates a temporary file:
>
> Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
> Const TemporaryFolder = 2
> Set tempFolder = FSO.GetSpecialFolder(TemporaryFolder)
> logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
> Set logFile = FSO.CreateTextFile(logFname, True)
> logFile.Close
>
> This appears to work on NT, Windows XP, Windows 2000, Windows 2003...
> except in a few cases where we've seen the value returned from
> ShortPath
> still has embedded spaces, e.g.
>
> C:\DOCUME~1\<username>\Local Settings\Temp\2
>
> Is this a known issue? Any workaround or suggestions on how to
> correct this?
>



Re: GetSpecialFolder(2).ShortPath not always returning fully-shortened by Michael

Michael
Thu May 17 18:21:45 CDT 2007

---snip
>> logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
---snip
>
> What happens when there are spaces in the path?

And why would the OP use .ShortPath in the first place? There is no
advantage over using .Path which seems the more common logical choice. The
.CreateTextFile method works just fine with path\file names with embedded
spaces and quoting is not required (or even supported) for any FSO methods.

--
Michael Harris
Microsoft.MVP.Scripting



Re: GetSpecialFolder(2).ShortPath not always returning fully-shortened by VogonP

VogonP
Fri May 18 08:25:02 CDT 2007

On May 17, 7:21 pm, "Michael Harris \(MVP\)" <mikhar.at.mvps.dot.org>
wrote:
> ---snip
>
> >> logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
> ---snip
>
> > What happens when there are spaces in the path?
>
> And why would the OP use .ShortPath in the first place? There is no
> advantage over using .Path which seems the more common logical choice. The
> .CreateTextFile method works just fine with path\file names with embedded
> spaces and quoting is not required (or even supported) for any FSO methods.
>
> --
> Michael Harris
> Microsoft.MVP.Scripting

We used ShortPath due to issues passing file names around; rather than
chasing down
all the consumers of our code it was more expedient to generate the
file names in short form.
I agree the *proper* approach here would be to turn the problem around
on the consumers
to fix their deficient code, but...this approach was working until
now.

Some Google searching produced a tidbit about a registry entry,
HKLM/System/CurrentControlSet/Control/FileSystem/
NfsDisable8dot3NameCreation
which, when set, appears to affect whether the TMP user environment
variable gets
shortened in a command window from what shows in the System/Advanced
editing
dialog for Environment. TMP, in turn, appears to affect the value
returned from
GetSpecialFolder(TemporaryFolder).ShortPath


urkec, I'm not sure whether you're asking if the PATH environment
variable makes any
difference in this scenario? If I recall, there were spaces in the
PATH.


In the long term, we'll chase down the consumers of this construct and
"encourage" them
to handle paths with embedded spaces properly. I was hoping to find
confirmation that
this issue (ShortPath not *fully* shortening the path) was a known
problem.

Thanks!


Re: GetSpecialFolder(2).ShortPath not always returning fully-short by urkec

urkec
Fri May 18 11:15:00 CDT 2007

"VogonP@gmail.com" wrote:
> urkec, I'm not sure whether you're asking if the PATH environment
> variable makes any
> difference in this scenario? If I recall, there were spaces in the
> PATH.
>

What happens when shortPath returns a path with spaces? The temporary file
doesn't get created? You get an error message?

--
urkec

Re: GetSpecialFolder(2).ShortPath not always returning fully-short by VogonP

VogonP
Fri May 18 12:55:58 CDT 2007

On May 18, 12:15 pm, urkec <u...@discussions.microsoft.com> wrote:
> "Vog...@gmail.com" wrote:
> > urkec, I'm not sure whether you're asking if the PATH environment
> > variable makes any
> > difference in this scenario? If I recall, there were spaces in the
> > PATH.
>
> What happens when shortPath returns a path with spaces? The temporary file
> doesn't get created? You get an error message?
>
> --
> urkec

The temp file is created, but the expectation is that "logFname" won't
have spaces when later
referenced.


Re: GetSpecialFolder(2).ShortPath not always returning fully-shortened by Alexander

Alexander
Fri May 25 22:06:10 CDT 2007

17.05.2007 22:49, VogonP@gmail.com schrieb:
> I've got a VBScript that has a section which creates a temporary file:
>
> Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
> Const TemporaryFolder = 2
> Set tempFolder = FSO.GetSpecialFolder(TemporaryFolder)
> logFname = FSO.BuildPath(tempFolder.ShortPath, FSO.GetTempName)
> Set logFile = FSO.CreateTextFile(logFname, True)
> logFile.Close
>
> This appears to work on NT, Windows XP, Windows 2000, Windows 2003...
> except in a few cases where we've seen the value returned from
> ShortPath
> still has embedded spaces, e.g.
>
> C:\DOCUME~1\<username>\Local Settings\Temp\2
>
> Is this a known issue? Any workaround or suggestions on how to
> correct this?

NTFS doesn't guarantee to provide a shortpath. It's something you can
fully disable, shortpathes are for backwards-compatibility to
non-LFN-Filesystems such as the FAT-32 version of early Win95.

So as for the NTFS-world don't rely on their existence, see:

"NtfsDisable8dot3NameCreation"
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/28231.mspx

MfG,
Alex