What this does is either copies or moves (your choice) any .SC2Replay files from the source folder to the destination folder, and renames it to remove any parentheses/number component after the map name and replaces that with a date-time string to make it unique.
UPDATE 1-11-2011: I updated the example "source" path in the script to reflect the change in patch 1.2.0 where unsaved multiplayer replays are now stored in the Unsaved\Multiplayer folder instead of just the Unsaved folder. See this post for details.
UPDATE 8-1-2010: I've added step-by-step instructions for setting up a scheduled task for either Windows 7/Vista or Windows XP.
UPDATE 7-31-2010: I have updated my date parser to work with most international locales. It reads date/time format information from the registry and has some exceptions (e.g. Arabic locales) for when the registry is not used. Very complex -- impossible to work with 100% of the weird locales out there, but it should work for the vast majority.
First copy the following line into Notepad and save it as something like "invisible.vbs" in any folder, just remember where you put it for later:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
This is a VBScript file that you call with Windows Scripting Host (wscript.exe). It allows you to run the batch file invisibly (normally a command prompt window would pop up briefly).
Next is the Windows Batch file that does all the actual work. Copy and paste this into Notepad and save it as a .bat file:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: Script to automatically copy or move SC2Replay files from the
:: Unsaved folder to the Multiplayer folder (or wherever you want).
::
:: NOTE: Set the "source" and "destination" paths for your account.
:: Set "action" to "move" if you want to move the files, or
:: "copy" to copy them.
::
:: Will not overwrite any existing files and names files uniquely
:: based on the date and time they were created.
::
:: NOTE! The date parser will work for most locales but not all.
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set source=C:\Users\USER\Documents\StarCraft II\Accounts\12345\1-A1-1-12345\Replays\Unsaved\Multiplayer
set destination=C:\Users\USER\Documents\StarCraft II\Accounts\12345\1-A1-1-12345\Replays\Multiplayer
set action=move
REM Gets date/time format information from registry
FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v iTime 2^>NUL') DO SET iTime=%%A
FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sDate 2^>NUL') DO SET sDate=%%A
FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v sTime 2^>NUL') DO SET sTime=%%A
FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v s1159 2^>NUL') DO SET s1159=%%A
REM Gets the list of files to copy from the source folder, doesn't actually copy yet
for /f "usebackq tokens=*" %%a in (`xcopy "%source%" "%destination%" /L /Y /I`) do (
if exist "%%a" (
REM Gets rid of number in parentheses after replay name
if %%~xa==.SC2Replay (
for /f "delims=0123456789( tokens=1" %%b in ("%%~na") do (
REM Gets rid of trailing space
set baseName=%%b##
set baseName=!baseName: ##=##!
set baseName=!baseName:##=!
)
REM Gets date/time modified.
REM Universal Date/Time parser
REM Works for most locales but not 100%
for /f "tokens=1*" %%c in ("%%~ta") do (
set modDate=%%c
set modTime=%%d
)
call :Get_Date
call :Get_Time
REM Output time format string - feel free to adjust
set destTime=!yy!!mm!!dd!-!hh!!mn!
set output=%destination%\!baseName! !destTime!.SC2Replay
if not exist "!output!" (
if "%action%"=="copy" (
echo Copying "%%a" to "!output!"...
copy "%%a" "!output!" /Y
) else (
echo Moving "%%a" to "!output!"...
move /Y "%%a" "!output!"
)
)
)
)
)
:: Uncomment next line to prompt you to hit a key before exiting so you can examine output
REM pause
goto :eof
:Get_Date
if "%modDate%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "usebackq skip=1 tokens=2-4 delims=(-)" %%a in (`echo:^|date`) do (
for /f "usebackq tokens=%toks% delims=%sDate% " %%d in ('%modDate%') do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
set toks=
)
)
goto :eof
:Get_Time
if "%modTime%A" LSS "A" (set toks=3) else (set toks=1)
for /f "usebackq tokens=%toks% delims=%sTime% " %%a in ('%modTime%') do (set AMPM=%%a)
if "%modTime%A" LSS "A" (set toks=1-2) else (set toks=2-3)
for /f "usebackq tokens=%toks% delims=%sTime% " %%a in ('%modTime%') do (
set hh=%%a
set mn=%%b
if "!AMPM!"=="AM" (
set s1159=AM
set iTime=0
) else (
if "!AMPM!"=="PM" (
set iTime=0
)
)
if "!iTime!"=="0" (
if "!AMPM!"=="%s1159%" (
if "!hh!"=="12" set hh=00
) else (
if "!hh:~0,1!"=="0" set hh=!hh:~1,1!
if not "!hh!"=="12" set /A hh=!hh!+12
)
)
set AMPM=
set toks=
)
goto :eof
Old version of the script is below for posterity:
+ Show Spoiler +
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: Script to automatically copy or move SC2Replay files from the
:: Unsaved folder to the Multiplayer folder (or wherever you want).
::
:: NOTE: Set the "source" and "destination" paths for your account.
:: Set "action" to "move" if you want to move the files, or
:: "copy" to copy them.
::
:: Will not overwrite any existing files and names files uniquely
:: based on the date and time they were created.
::
:: NOTE! I doubt this will work properly on anything but standard US
:: English locales because the date parser I wrote specifically for
:: the standard US English date format.
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set source=C:\Users\USER\Documents\StarCraft II Beta\Accounts\12345\1-A1-1-12345\Replays\Unsaved
set destination=C:\Users\USER\Documents\StarCraft II Beta\Accounts\12345\1-A1-1-12345\Replays\Multiplayer
set action=move
REM Gets the list of files to copy from the source folder, doesn't actually copy yet
for /f "usebackq tokens=*" %%a in (`xcopy "%source%" "%destination%" /L /Y /I`) do (
if exist "%%a" (
REM Gets rid of number in parentheses after replay name
if %%~xa==.SC2Replay (
for /f "delims=( tokens=1" %%b in ("%%~na") do (
REM Gets rid of trailing space
set baseName=%%b##
set baseName=!baseName: ##=##!
set baseName=!baseName:##=!
)
REM Gets date/time modified.
REM Standard US English Date/Time parser, tweak if you
REM use a non-standard date/time format or locale.
REM Converts from "Sun 7/11/2010 01:50 PM" to "20100711-1350"
for /f "tokens=1-6 delims=/: " %%c in ("%%~ta") do (
set hour=%%f
set AMPM=%%h
if "!AMPM!"=="AM" (
if "!hour!"=="12" set hour=00
) else (
if "!AMPM!"=="PM" (
if "!hour:~0,1!"=="0" set hour=!hour:~1,1!
if not "!hour!"=="12" set /A hour=!hour!+12
)
)
set modTime=%%e%%c%%d-!hour!%%g
set output=%destination%\!baseName! !modTime!.SC2Replay
if not exist "!output!" (
if "%action%"=="copy" (
echo Copying "%%a" to "!output!"...
copy "%%a" "!output!" /Y
) else (
echo Moving "%%a" to "!output!"...
move /Y "%%a" "!output!"
)
)
)
)
)
)
)
:: Uncomment next line to prompt you to hit a key before exiting so you can examine output
REM pause
Modify the lines for "source", "destination" and if need be, "action" as it applies to your system and whether you want to MOVE or COPY the replay files.
Next you'll want to schedule a task to run the script every 5 minutes or so. There are two separate guides below, one for Windows 7/Vista and one for XP. Expand the appropriate spoiler and continue with the steps.
Task Scheduler Setup (Windows 7/Vista):
+ Show Spoiler +
- Click the Start button on the taskbar.
- Type "Task Scheduler" in the Search box and click the first result that says Task Scheduler.
- Expand the Task Scheduler Library folder in the list pane on the left.
- Right click the Task Scheduler Library folder and choose "New Folder". Give it a name like My Custom Tasks.
- Right click your new folder and choose "Create Task" (not "Create Basic Task", we want a little more flexibility than what the basic wizard offers).
- Enter a name like "SC2 Replay Backup" for the Name and a description if you want.
- Click the Triggers tab.
- Click New.
- For "Begin the task", choose "At log on".
- Select Specific user and it will only run when you are logged in.
- Under Advanced Settings, check Repeat task every and choose "5 minutes" for the first box and a duration of "Indefinitely" for the second box.
- Click OK.
- Click the Actions tab.
- Click New.
- Type wscript.exe in the Program/script box.
- In the Arguments box type the following, substituting your own paths to the script files you created earlier:
"C:\path to\invisible.vbs" "C:\path to\sc2replays.bat"
Include the quotes around each argument. - Click OK twice
- Log out of your machine (or restart) and log back in.
The task should now be active and will run every 5 minutes as long as you are logged in. You can always disable the task from the Task Scheduler. You might want to add another trigger where "Begin the task" is set to "At task creation/modification". This will cause the task to begin again whenever you modify it, otherwise you will have to log off and back in to re-enable it after disabling it. (You can't just right click and run the task, because doing it that way only runs it once, not every 5 minutes.)
Scheduled Tasks Setup (Windows XP):
+ Show Spoiler +
- Click the Start button on the task bar.
- Click Run...
- Type "control schedtasks" (minus quotes) in the box and click OK. This is a shortcut to the Scheduled Tasks applet.
- Go to File-New-Scheduled Task. This bypasses the useless "Add Scheduled Task" wizard.
- Give the new task a name like SC2 Replay Backup
- Right click the new task and choose Properties
- In the Run box enter the following, substituting your own paths to the script files you created earlier:
wscript.exe "C:\path to\invisible.vbs" "C:\path to\sc2replays.bat"
Include the quotes around each argument. - Check the "Run only if logged on" box.
- Click the Schedule tab
- Leave the Schedule Task box as "Daily". Adjust the Start time to a few minutes from now, or whenever you want the script to start the very first time. We'll set it up to run continuously so this doesn't matter too much.
- Click the Advanced button.
- Check the Repeat task box.
- Change the interval to every 5 minutes, or as often as you like.
- Change the duration box to 24 hours.
- Click OK.
- Click the Settings tab.
- Uncheck "Stop the task if it runs for..."
- Click OK.
The task should now be scheduled to run the very first time at the time you specified and after that will run every 5 minutes as long as you are logged in. You can always disable the task from Start-Control Panel-Scheduled Tasks.
Observations:
I have found that if you are using "move" mode, and you are viewing a replay it hasn't moved yet, it will gracefully fail to move the file and will succeed the next time it runs after you are no longer viewing it.
One issue I found is that if the script moves a replay from the Unsaved folder in-game while you are browsing it, the interface might glitch out a little. Just run a different replay or restart the game.
Feel free to PM me if you have any issues.