tags:

views:

28

answers:

2

I want to be able to generate random strings from the windows command prompt. This is so that i can create a temp file with that random name so that i am sure that the temp file absolutely does not exist.

Is this possible?

+1  A: 

This isn't possible via the normal command prompt. However, you could write a script to accomplish the task.

If you were using powershell this woul be simple:

$tempFileName = [System.IO.Path]::GetTempFileName()

generates (for Windows 7)

C:\Users\Username\AppData\Local\Temp\tmpAE1C.tmp

fletcher
thanks Fletcher!
Santhosh
A: 

I finally wrote something like this..not very neat, but nevertheless serves the purpose.

setlocal enabledelayedexpansion

set TMP_COUNT=0
:GET_TEMP_FILE
    if exist temp!TMP_COUNT!.txt (
        set /a TMP_COUNT+=1
        goto GET_TEMP_FILE
    ) 

    setlocal disabledelayedexpansion
echo temp file name is : temp!TMP_COUNT!.txt
Santhosh
You don't need delayed expansion here.
Joey
yes! thanks Joey
Santhosh