variablesbatch-filesetx

How do i replace space in environment variable (batch)


I am using this code to create an environment variable with the current date and time:

setx timestamp "%DATE:/=-%@%TIME::=-%"

The effect of using this command is to create a string value "timestamp" in HKCU\Environment with the data value "Fri 26-04-2013@18-32-31.29".

What i want is to remove that space from "FRI" and "26-04-2013@18-32-31.29" to make it "Fri-26-04-2013@18-32-31.29".

Thanks


Solution

  • Try this:

     set timestamp="%DATE:/=-%@%TIME::=-%"
     set timestamp=%timestamp: =-%
     setx timestamp %timestamp% /K HKEY_CURRENT_USER\ENVIRONMENT