A
Angel Tsankov
How can I get a name for a temporary file in a .bat file?
Angel said:How can I get a name for a temporary file in a .bat file?
Phil Robyn said:OK, I'll bite.
Can you elaborate a bit? Give some more detail about what you
want to do?
What do you mean by 'get'?
What is a 'temporary file'?
Todd said:In other words, is the temp file created by some program or are you trying
to generate a random filename to use for your own temp files?
How can I get a name for a temporary file in a .bat file?
Phil Robyn said:Oh, Todd, you have such a way with words!
William said:"Angel Tsankov" wrote in message
In WSH (Windows Script Host), the GetTempName method
is provided for exactly this purpose. For example, the following
line of VBS code will display the result of GetTempName:
WScript.Echo CreateObject("Scripting.FileSystemObject").GetTempName
However, to run this command and retrieve the result in a variable
itself needs a workfile (containing the VBS code), which begs the
question.
As an alternative approach, which doesn't require a workfile,
is to use the RANDOM variable to generate a workfile name.
The following code shows how to create a temporary workfile
name of format WRKnnnnn.TMP that doesn't conflict with any
existing file, and loads it into the variable WorkFile:
Lines that aren't prefixed with two spaces have wrapped in transmission
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL
:LOOP
SET /a WorkFile=%RANDOM%+100000
SET WorkFile=WRK%WorkFile:~-5%.TMP
IF EXIST %WorkFile% GOTO LOOP
ECHO. Your temporary workfile name is %WorkFile%
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
The following screen capture assumes the above is pasted into DEMO.BAT
============Screen capture Windows 2000 simulated in Win95
C:\WORK>demo
Your temporary workfile name is WRK12947.TMP
C:\WORK>
============End screen capture
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/
Todd said:Sorry. First thing that came to mind was, either we would see a textbook
response to your final question, or an extremely long response unrelated to
the actual task. Oh well.