Code: Select all
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=/" %%A in ('powershell -command "Get-Date -Format 'yyyy/MM/dd'"') do (
set "year=%%A"
set "month=%%B"
set "day=%%C"
)
set "output_file=S:\Configs\HotkeyP\settings\%year% %month% %day%.reg"
set "output_file=!output_file:-= !"
set "output_file=!output_file: =!"
reg export "HKEY_CURRENT_USER\SOFTWARE\Petr Lastovicka\hotkey" "%output_file%"
endlocal
Code: Select all
YYYY MM DD.reg
Code: Select all
2023 03 17.reg
But if I change that one crucial line to either
Code: Select all
set "output_file=C:\Users\YOUR-USER-NAME\Documents\%year% %month% %day%.reg"
Code: Select all
set "output_file="%userprofile\Documents\%year% %month% %day%.reg""
Code: Select all
-
Code: Select all
YOUR-USER-NAME
Code: Select all
YOUR USER NAME
I have tried using double quotes vs. single ones, capitals vs. lower case, running the BAT from volume C instead from S - but the only thing that helps is just changing that line to e.g.
Code: Select all
set "output_file=C:\Temp\%year% %month% %day%.reg"
Code: Select all
set "output_file=C:\Users\Temp\%year% %month% %day%.reg"
So what is happening here? How can I write a REG file to my Documents system folder with such simplistic code
Code: Select all
reg export "HKEY_CURRENT_USER\SOFTWARE\Petr Lastovicka\hotkey" "C:\Users\YOUR-USER-NAME\Documents\HotkeyP settings.reg"