-2

So I have a very simple script set up on the task scheduler to move screenshots once a day from one folder to another. Thats working fine, but when the screenshots are taken, they are automatically give a name by Steam, e.g. "Screenshot.png", "Screenshot 1.png", "Screenshot 2.png" etc depending on how many are in the folder. So when the files are emptied in to the other folder each day, every set of screenshots taken on that day start again at "Screenshot.png" and go up from there. The result is that when they are moved, they are going to be either overwriting or appending (1) or something (not sure which as haven't had this running yet!)

So I want to change the following batch file to find the highest number in "Screenshot xxx.png" in the destination folder, add one, rename the file in the source folder to this number and then do the move. This will have to fit in a loop so it can go through all files in the source folder.

@echo off

set X=1

set "source=C:\Users\Leigh\AppData\Local\Colossal Order\Cities_Skylines\Screenshots"

set "destination=D:\Leigh\Pictures\SkyLinesScreenshots"

robocopy "%source%" "%destination%" /mov

exit /b

I had a play and found a script to determine which the next number should be, but couldnt get the regex right:

@echo off
    setlocal enableextensions disabledelayedexpansion

    setlocal enabledelayedexpansion
    set "nextFile=0" & for /f "delims=" %%a in ('
        findstr  /b /r /x 
                       /c:"\bScreenshot\b\s[0-9]+\.png"
    ') do if %%~na geq !nextFile! set /a "nextFile=%%~na+1"
    endlocal & set "nextFile=%nextFile%"

    echo Next file will be: %nextFile%

If I get that right I will integrate them together and work out the problem. This is pretty clear what needs doing, so could anyone either give me the correct regex, or even more if they so wish.

Thanks in Advance!

  • Never delete `...s\Screenshots\*.png` and `%windir%\system32\xcopy.exe /m "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Screenshots\*.png" "%HOME%\Pictures\SkyLinesScreenshots"` – somebadhat Apr 26 '20 at 13:18

2 Answers2

0

Windows 10 64-bit. PowerShell 5

Archive screenshots to timestamp folder (mmddyy) using CMD and robocopy. Delete archives older than 14 days with PowerShell.

@echo off
setlocal enableextensions
set "source=C:\Users\Leigh\AppData\Local\Colossal Order\Cities_Skylines\Screenshots"
set "destination=D:\Leigh\Pictures\SkyLinesScreenshots\%DATE:~-10,2%%DATE:~-7,2%%DATE:~-4,2%"
robocopy "%source%" "%destination%" /mov
rem delete archives older than 14 days. Remove -whatif 
powershell -command "get-childitem "D:\Leigh\Pictures\SkyLinesScreenshots" |? {$_.psiscontainer -and $_.lastwritetime -lt (get-date).adddays(-14)} |% {remove-item $_ -recurse -force -whatif}"
exit /b

You can adjust the age threshold through .adddays. This is in WhatIf mode. Remove -whatif to delete the folders.

somebadhat
  • 744
  • 1
  • 5
  • 17
0

Windows 10 64-bit

Count, increment, move w/ rename with Windows 10 64-bit CMD, for, set, and move.

If the source screenshots are created without enough interval this will happen:

screenshot cmd

Remove the echo when it is working.

CMD:

@rem Count, increment, move w/ rename with Windows 10 64-bit CMD, for, set, and move 
cmd /q /v /e
pushd "%HOME%\Pictures\SkyLinesScreenshots"
FOR /f %g in ('dir /a-d ^| find "File(s)"') do set z=%g
cd "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Screenshots"
FOR /f "delims=" %g in ('DIR /b /a-d') do (
   set /a z+=1 > nul
   echo move "%g" "%HOME%\Pictures\SkyLinesScreenshots\screenshot!z!.png" 
) 
popd
exit /b 

Script:

@rem Count, increment, move w/ rename with Windows 10 64-bit CMD, for, set, and move
@echo off
setlocal enableextensions 
pushd "%HOME%\Pictures\SkyLinesScreenshots"
FOR /f %%g in ('dir /a-d ^| find "File(s)"') do set z=%%g
cd "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Screenshots"
FOR /f "delims=" %%g in ('DIR /b /a-d') do (
   set zname=%%g
   Call :increment 
) 
popd
exit /b 

:increment
set /a z+=1 > nul
echo move "%zname%" "%HOME%\Pictures\SkyLinesScreenshots\screenshot%z%.png" 
exit /b

Results:

screenshot cmd results

somebadhat
  • 744
  • 1
  • 5
  • 17