top of page
This is a command line script with embeded powershell​
It manages the Steam version of the Dwarf Fortress game save folder
by using robocopy to copy files to and from a cloud save location that you define
basically it runs the following commands

robocopy "your cloud save location\save" "steam folder for df\save" *.* /dcopy:dat /xo /s
run game and wait for it to finish
robocopy "steam folder for df\save" "your cloud save location\save" *.* /dcopy:dat /xo /s
NOTE: it can take a while to create the backups

you can put  > nul  at the end of the robocopy commands to get a cleaner output

@echo off

setlocal

setlocal enabledelayedexpansion

set robocopySwitches=/dcopy:dat /xo /s

set RegVariables=HKCU\Variables

set RegSteamDF=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 975370

set "dfpath=no"

for /F "usebackq tokens=2,* skip=2" %%L IN (

    `reg query "%RegVariables%" /v syncPath`

) do set "dfSyncPath=%%M"

set "PScommand="^

        POWERSHELL -noprofile Add-Type -AssemblyName System.Windows.Forms;^

        $FolderBrowse = New-Object System.Windows.Forms.OpenFileDialog -Property @{^

            ValidateNames = $false;^

            InitialDirectory = '!dfSyncPath!';^

            CheckFileExists = $false;^

            RestoreDirectory = $true;^

            FileName = 'Selected Folder';^

        };^

        $null = $FolderBrowse.ShowDialog();^

        $FolderName = Split-Path -Path $FolderBrowse.FileName;^

        Write-Output $FolderName""

for /F "usebackq tokens=2,* skip=2" %%L IN (

    `reg query "%RegSteamDF%" /v InstallLocation`

) do set "dfpath=%%M"

cls

if "!dfpath!" NEQ "no" (

    @rem Game info found in registry

    powershell -noprofile write-host -back yellow   -fore black Select a location to sync Dwarf Fortress saves folder

    powershell -noprofile write-host -fore magenta This will be the location where the Dwarf Fortress game saves folder will be copied

    powershell -noprofile write-host -fore yellow .. So c:\users\you\dropbox\DwarfFortress will end up with c:\users\you\dropbox\DwarfFortress\save

    powershell -noprofile write-host -fore magenta If for some reason the cloud share does not have the save folder

    powershell -noprofile write-host -fore yellow .. the Dwarf Fortress game saves folder will be copied after you quit Dwarf Fortress

    if defined dfSyncPath (

        @rem save game folder path found in registry

        powershell -noprofile write-host -back black -fore green currently it is   !dfSyncPath!   click cancel to keep using it

        for /F "usebackq tokens=*" %%Q in (`%PScommand%`) do set folder=%%Q

        if not defined folder (set folder=!dfSyncPath!)

    ) else (

        @rem looks like first time the script is run on this machine

        @echo ====================================================

        powershell -noprofile write-host -fore yellow Select a cloud share folder on a system like dropbox

        powershell -noprofile write-host -fore magenta If you already have a save folder in that location

        powershell -noprofile write-host -fore yellow .. the contents of the save directory will be copied do your Dwarf Fortress game save folder

        powershell -noprofile write-host -fore magenta If you do not have a save folder in that location

        powershell -noprofile write-host -fore yellow .. the Dwarf Fortress game saves folder will be copied after you quit Dwarf Fortress

        for /F "usebackq tokens=*" %%Q in (`%PScommand%`) do set folder=%%Q

        if not defined folder (goto :noFolderSelected)

    )

) else (

    @rem no registry info for game

    powershell -noprofile write-host -back yellow -fore black Can not find Dwarf Fortress registry information

    powershell -noprofile write-host -fore magenta  note - This script is for the Steam Version

    powershell -noprofile write-host -fore yellow .. it uses the registry to get the game information

    powershell -noprofile write-host -fore blue .. %RegSteamDF%

    goto finished

)

set "Mytime=!time: =0!"

set dt=!DATE:~10,4!-!DATE:~7,2!-!DATE:~4,2!_!mytime:~0,2!-!time:~3,2!-!time:~6,2!

set dtc=!computername!_!dt!

@echo ----------------------------------------------------

powershell -noprofile write-host -fore magenta Backing up your local game DF save file

powershell -noprofile write-host -fore yellow ..  '!dfpath!\save'

echo to

powershell -noprofile write-host -fore yellow ..  'c:\temp\df\save_!dt!'

robocopy "!dfpath!\save" "c:\temp\df\save_!dt!" *.* !robocopySwitches! 

@echo ----------------------------------------------------

powershell -noprofile write-host -fore magenta Backing up for safe keeping

powershell -noprofile write-host -fore yellow ..  '!folder!\save'

echo to

powershell -noprofile write-host -fore yellow ..  '!folder!\saved-backups\!dtc!'

robocopy "!folder!\save" "!folder!\saved-backups\!dtc!" *.* !robocopySwitches!

reg add "!RegVariables!" /v syncPath /t REG_SZ /d "!folder!" /f > nul

if exist !folder!\save (

    @echo ----------------------------------------------------

    powershell -noprofile write-host -back yellow -fore black 'Copying !folder!\save to !dfpath!\save'

    robocopy "!folder!\save" "!dfpath!\save" *.* !robocopySwitches!

)

@echo ----------------------------------------------------

powershell -noprofile write-host -back yellow -fore black Starting Dwarf Fortress

start "" /wait /d "!dfpath!" "Dwarf Fortress.exe"

@echo ----------------------------------------------------

powershell -noprofile write-host -back yellow -fore black Copying Dwarf Fortress save folder to !folder!\save

robocopy "!dfpath!\save" "!folder!\save" *.* !robocopySwitches! 

goto finished

:noFolderSelected

    echo cancelled - no folder selected - clossing script

:finished

    endlocal

    pause

Setup the script

  • Create a file on your desktop called run_DF.cmd and then edit it

  • copy and paste all the contents of the above script into the file

  • save the script and then just double click it

Run the script

  • The script will ask you to select a location (like dropbox) to save your game save folder

  • If a save folder exists at that location it will be copied to the Dwarf Fortress game save folder

  • It will run Dwarf Fortress.

  • When you Quit it will copy the save game folder to your cloud save location.

DF Script end.png

© 2024 by OneManCoder

bottom of page