The GW-Scripting list is a discussion list for information regarding the development and use of Window-Eyes scripts. Any subscriber of the GW-Scripting list has the ability to post on-topic messages.

From:

 "David" <elephant@tele2.no>

Subject:

 Re: Creating temporary files?

Date:

 Mon, Jun 25, 2012 9:37:04 pm
This is a multi-part message in MIME format.

------=_NextPart_000_01A2_01CD534C.F41F3C00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks to all.
Code is working now. Chip, your first sample was exactly what I was looking out for.


----- Original Message -----
From: Chip Orange
To: gw-scripting@gwmicro.com
Sent: Tuesday, June 26, 2012 2:33 AM
Subject: RE: Creating temporary files?


Hi David,

What you needed was to expand the contens of the temp dir name again, because it contained an environment variable (the part surrounded with percent signs), which was also originally the what you did to the %temp% environment variable.

Below are several different ways I've picked up from others to generate random file names, or place a file name of your choosing in the temporary dir:

' this one puts the name of your choosing into the temp dir
set oShell = createObject("wScript.shell")
tmpFileName = oShell.ExpandEnvironmentStrings("%temp%") & "myTemp.tmp"

' and so does this one
Set SO_Env = SharedObjects("com.GWMicro.GWToolkit.Env", 0)
tmpFileName = SO_Env("%temp%") & "myTemp.tmp"

' this one actually generates the random file name which it puts in the temp dir
Set oSystem =CreateObject("Scripting.FileSystemObject")
const tempDirName=2
tmpFileName = oSystem.GetSpecialFolder(tempDirName).path & "" & oSystem.GetTempName()




hth,

Chip



----------------------------------------------------------------------------

From: David [mailto:elephant@tele2.no]
Sent: Monday, June 25, 2012 2:44 AM
To: gw-scripting@gwmicro.com
Subject: Creating temporary files?


Listers,
Does anyone here happen to have a simple snip-it code, for the following scenario? Or any good suggestions?

I have an app, that creates a temporary file for a certain task. The creation of the file has worked fine so far. But since this is only a temporary file, I had hoped to find a way of storing it in the Temporary folder on the computer. That is, the folder that is defined in the environment variable as either "tmp" or "temp", in Windows itself.

I did a bit of research on the net, and found a way to retrieve the contents of the Temp variable. Here is that code:

Dim Shell: Set Shell = CreateObject( "WScript.Shell")
Dim Environment: Set Environment = Shell.Environment( "System")
Dim Tmp: Tmp = Environment( "Temp")

The code works fine, and returns the contents of the variable. Problem is, that it returns things like:
%systemroot%Temp
. Now trying a command like:
Dim FSO: Set FSO = CreateObject( "Scripting.FileSystemObject" )
Dim F: Set F = FSO.OpenTexstFile( Tmp &"MyFile.tmp", 2, True)
, I get an error thrown at me, telling that the path is invalid. My guess is, that the OpenTextFile does not like the %SystemRoot% part of the created filename.

Reason why I tried to get hold of the Temp variable of the OS, is that I then could have the file stored in the temporary folder, no matter which machine the app was running on. Is there some kind of property or method, that will handle the expansion of the %systemroot% into a valid path? We migh even think of situations where the part between the two percent-signs could be anythhing else, depending on the computer configuration.

Hope all of this makes any sense. Any good workaround here?

Thanks,

------=_NextPart_000_01A2_01CD534C.F41F3C00
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19258">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Thanks to all.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Code is working now. Chip, your first sample was
exactly what I was looking out for.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=lists3717@comcast.net href="mailto:lists3717@comcast.net">Chip
Orange</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=gw-scripting@gwmicro.com
href="mailto:gw-scripting@gwmicro.com">gw-scripting@gwmicro.com</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, June 26, 2012 2:33
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: Creating temporary
files?</DIV>
<DIV><BR></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>Hi David,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>What you needed was to expand the contens of the temp dir
name again, because it contained an environment variable (the part surrounded
with percent signs), which was also originally the what you did to the %temp%
environment variable.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>Below are several different ways I've picked up from others
to generate random file names, or place a file name of your choosing in the
temporary dir:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>' this one puts the name of your choosing into the temp
dir</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>set oShell = createObject("wScript.shell")<BR>tmpFileName =
oShell.ExpandEnvironmentStrings("%temp%") &amp;
"myTemp.tmp"</FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN
class=939002900-26062012></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN class=939002900-26062012>'
and so does this one</SPAN></FONT></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>Set SO_Env = SharedObjects("com.GWMicro.GWToolkit.Env",
0)<BR>tmpFileName = SO_Env("%temp%") &amp; "myTemp.tmp"<BR>&nbsp;&nbsp;&nbsp;
</FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN class=939002900-26062012>'
this one actually generates the random file name which it puts in the temp
dir</SPAN></FONT></DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial>Set oSystem
=CreateObject("Scripting.FileSystemObject")<BR>const
tempDirName=2<BR>tmpFileName =&nbsp;
oSystem.GetSpecialFolder(tempDirName).path &amp; "" &amp;&nbsp;
oSystem.GetTempName()</FONT></SPAN></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=939002900-26062012><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV><FONT color=#0000ff size=2
face=Arial></FONT><BR>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><SPAN
class=939002900-26062012><FONT color=#0000ff size=2
face=Arial>&nbsp;hth,</FONT></SPAN></DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><SPAN
class=939002900-26062012></SPAN>&nbsp;</DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><SPAN
class=939002900-26062012><FONT color=#0000ff size=2
face=Arial>Chip</FONT></SPAN></DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><SPAN
class=939002900-26062012></SPAN>&nbsp;</DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><SPAN
class=939002900-26062012></SPAN>&nbsp;</DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
</DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left><FONT size=2
face=Tahoma><B>From:</B> David [mailto:elephant@tele2.no] <BR><B>Sent:</B>
Monday, June 25, 2012 2:44 AM<BR><B>To:</B>
gw-scripting@gwmicro.com<BR><B>Subject:</B> Creating temporary
files?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT size=2 face=Arial>Listers,</FONT></DIV>
<DIV><FONT size=2 face=Arial>Does anyone here happen to have a simple
snip-it code, for the following scenario? Or any good
suggestions?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>I have an app, that creates a temporary file
for a certain task. The creation of the file has worked fine so far. But
since this is only a temporary file, I had hoped to find a way of storing it
in the Temporary folder on the computer. That is, the folder that is defined
in the environment variable as either "tmp" or "temp", in Windows itself.
</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>I did a bit of research on the net, and found a
way to retrieve the contents of the Temp variable. Here is that
code:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>&nbsp;Dim Shell: Set Shell = CreateObject(
"WScript.Shell")<BR>&nbsp;Dim Environment: Set Environment =
Shell.Environment( "System")<BR>&nbsp;&nbsp;&nbsp; Dim Tmp: Tmp =
Environment( "Temp")</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>The code works fine, and returns the contents
of the variable. Problem is, that it returns things like:</FONT></DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp;
%systemroot%Temp</FONT></DIV>
<DIV><FONT size=2 face=Arial>. Now trying a command like:</FONT></DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp; Dim FSO: Set FSO =
CreateObject( "Scripting.FileSystemObject" )</FONT></DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp; Dim F: Set F =
FSO.OpenTexstFile( Tmp &amp;"MyFile.tmp", 2, True)</FONT></DIV>
<DIV><FONT size=2 face=Arial>, I get an error thrown at me, telling that the
path is invalid. My guess is, that the OpenTextFile does not like the
%SystemRoot% part of the created filename.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Reason why I tried to get hold of the Temp
variable of the OS, is that I then could have the file stored in the
temporary folder, no matter which machine the app was running on. Is there
some kind of property or method, that will handle the expansion of the
%systemroot% into a valid path? We migh even think of situations where the
part between the two percent-signs could be anythhing else, depending on the
computer configuration. </FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Hope all of this makes any sense. Any good
workaround here?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Thanks,</FONT></DIV>
<DIV>&nbsp;</DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_01A2_01CD534C.F41F3C00--