(view source code of maketemp.bat as plain text)
@ECHO OFF
:: Not for Windows 9* or MS-DOSIF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Only one argument allowedIF NOT "%~2"=="" GOTO Syntax
:: Check if FINDSTR is availableFINDSTR /? >NUL 2>&1 || GOTO Syntax
:: Allowed argument is a variable name, check for invalid charactersECHO.%1| FINDSTR /R /I /C:"[^0-9a-z\._-]" >NUL && GOTO Syntax
:: Use local variableSETLOCAL ENABLEDELAYEDEXPANSION
:: Use the default if no variable name was specifiedIF NOT "%~1"=="" (SET VarName=%~1) ELSE (SET VarName=TempFile)
:Again:: Use creation time as prefix:: Note: spaces are replaced by zeroes, a bugfix by Michael KrailoSET TempFile=~~%Time: =0%
:: Remove time delimitersSET TempFile=%TempFile::=%
SET TempFile=%TempFile:.=%
SET TempFile=%TempFile:,=%
:: Create a really large random number and append it to the prefixFOR /L %%A IN (0,1,9) DO SET TempFile=!TempFile!!Random!
:: Append .tmp extensionSET TempFile=%TempFile%.tmp
:: If temp file with this name already exists, try again, otherwise create it nowIF EXIST "%Temp%.\%TempFile%" (
GOTO Again
) ELSE (
TYPE NUL > "%Temp%.\%TempFile%" || SET TempFile=
):: Retrieve the fully qualified path of the new temp fileFOR %%A IN ("%Temp%.\%TempFile%") DO SET TempFile=%%~fA
:: Display the fully qualified path of the new temp fileSET TempFile
:: Return the fully qualified path of the new temp fileENDLOCAL & SET %VarName%=%TempFile%
:: DoneGOTO:EOF
:SyntaxECHO.
ECHO MakeTemp.bat, Version 2.10 for Windows 2000 and later
ECHO Create a new temporary file with a unique name, and return
ECHO its fully qualified path in an environment variable
ECHO.
ECHO Usage: MAKETEMP [ variable_name ]
ECHO.
ECHO Where: variable_name is the optional name of the environment
ECHO variable that will contain the returned
ECHO path (default: "TempFile")
ECHO.
ECHO Notes: The fully qualified path of the temporary file will be
ECHO stored in an environment variable named as specified on
ECHO the command line, or named "TempFile" if not specified.
ECHO If a temporary file could not be created, the variable
ECHO will be empty (undefined).
ECHO This batch file has been tested in Windows XP only; it
ECHO will probably work in Windows 2000 too; to make it work
ECHO in Windows NT 4, the Resource Kit utility FINDSTR must
ECHO be installed and in the PATH.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" ENDLOCAL
IF "%OS%"=="Windows_NT" COLOR 00
page last modified: 2025-10-11; loaded in 0.0103 seconds