Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a new directory and copy a file into the folder using DOS batch file

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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%"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading