# DOS batch file copies "Anki2" folder to specified location

**URL:** <https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569>\
**Category:** Help\
**Created:** [March 24, 2022, 9:58am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569 "2022-03-24T09:58:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![OldGrantonian](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/oldgrantonian/32/986_2.png) [@OldGrantonian](https://forums.ankiweb.net/u/OldGrantonian)\
**Post date:** [March 24, 2022, 9:58am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569/1 "2022-03-24T09:58:53Z")

</div>

.  
The following DOS batch file copies the contents of your “Anki2” in C: to any folder of your choice. Within that folder, each run creates a new folder with today’s date, such as: “2022\_03\_24”

sd = source directory  
dd = destination directory

As usual for backups, CLOSE Anki first. Maybe a pro can add a line to close Anki. But it needs to be an orderly procedure, you can’t simply kill the process - as in Task Manager.

If you run the prog twice on the same day, I suppose it will simply overwrite whatever was previously there, so there might not be any harm done. It’s up to you.

I only understand the first few lines of the prog. If anyone wants to provide a translation - please do.

Remember to edit your Username in third line: Set “sd…”

.

```auto
REM This bat copies files from sd to dd
@Echo Off
Set "sd=C:\Users\<me>\AppData\Roaming\Anki2
Set "dd=E:\Documents\Data\1SoftwareRelated\Backups\Anki2"
Set "ds="
If Not Exist "%sd%\" Exit /B
For /F "Tokens=1-3Delims=/ " %%A In ('RoboCopy/NJH /L "\|" Null'
) Do If Not Defined ds Set "ds=%%A_%%B_%%C"
If Not Defined ds Exit /B
RoboCopy "%sd%" "%dd%\%ds%" /E
Pause

```

.  
Thanks  
.

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [March 25, 2022, 12:52am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569/2 "2022-03-25T00:52:41Z")

</div>

> [@OldGrantonian](#):
>
> `Set "sd=C:\Users\<me>\AppData\Roaming\Anki2`

Can be replaced by:

```auto
Set "sd=%USERPROFILE%\AppData\Roaming\Anki2

```

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [March 25, 2022, 8:36am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569/3 "2022-03-25T08:36:11Z")

</div>

What is your use for this? Isn’t it simpler to use Anki’s native export feature? That only copies the files you actually need to restore your collection, and creates a single file.

---

<div class="post-metadata">

**Author:** ![OldGrantonian](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/oldgrantonian/32/986_2.png) [@OldGrantonian](https://forums.ankiweb.net/u/OldGrantonian)\
**Post date:** [March 25, 2022, 10:30am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569/4 "2022-03-25T10:30:51Z")

</div>

.

> [@Rumo](#):
>
> What is your use for this?

.  
The main reason was to keep backups in separate folders. The name of the folder is a date, such as “2022\_03\_25”.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 4:27am UTC](https://forums.ankiweb.net/t/dos-batch-file-copies-anki2-folder-to-specified-location/18569/5 "2023-05-01T04:27:55Z")

</div>

Closed on May 1, 2023, 4:27am UTC


