create unique string in batch

Simplest:

set FILENAME=basename-%RANDOM%

Better way:

    for /f "delims=:. tokens=1-4" %%t in ("%TIME: =0%") do (
        set FILENAME=basename-%%t%%u%%v%%w
    )

Best way:

    for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
        for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (
            set FILENAME=basename-%%c-%%b-%%a-%%m%%n%%o%%p
        )
    )

Reference: http://blogs.msdn.com/b/myocom/archive/2005/06/03/creating-unique-filenames-in-a-batch-file.aspx

你可能感兴趣的:(batch)