I use a date variable to create a new folder like this:
@echo
cd \
D:
cd "D:\My Projects\Test"
For /f "tokens=1-4 delims=/ " %%d in ("%date%") DO MD "NPP file backup %%g%%e%%f"
:END
It gives me this result:
D:\My Projects\Test\NPP file backup 20240125
How can I specify the newly created folder as the target destination in a copy command? I want to incorporate it into the my batch file.
File is located here:
"C:\Users{Username}\AppData\Roaming\NPP\Shortcuts.xml"
I tried:
set target="D:\My Projects\Test\NPP file backup %%g%%e%%f"
COPY "C:\Users\{Username}\AppData\Roaming\NPP\Shortcuts.xml" %target%
It’s not working at all. Certainly no expert with DOS scripting, any help would be appreciated.
>Solution :
%%e, %%f, and %%g stop existing when the for loop ends. If you want to be able to use these values later on in the script, you’ll need to store them in a regular variable.
@echo off
cd /d "D:\My Projects\Test"
for /f "tokens=1-4 delims=/ " %%d in ("%date%") do set "target=NPP file backup %%g%%e%%f"
mkdir "%target%"
copy "%appdata%\Notepad++\Shortcuts.xml" "%target%"