Advertisement
Ben_S

Maxto M3 - Archive Movie FIles

Aug 29th, 2022 (edited)
1,571
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.92 KB | Source Code | 0 0
  1. @ECHO OFF
  2. REM This will copy files from the Maxto camera to a subfolder under
  3. REM the drive letter an path the batch file is launched from.
  4. REM It uses the date pattern in the filename to determine what folder
  5. REM to copy the files to.  If it is looking for a folder named
  6. REM 20220429 and finds 20220429_North_Park it is smart enough
  7. REM to use the existing folder.
  8. REM
  9. REM This will show you the dates of the media currently stored on the camera.
  10. REM The user can use this to determine how many days back they want to copy.
  11. REM
  12. REM This method does not copy files as fast and bulk copying with File Explorer,
  13. REM but it is automated and you don't have to focus on it while you get other
  14. REM things done.
  15. REM
  16. REM Ben Sacherich - 4/29/2022 - https://www.facebook.com/groups/maxtom3
  17. REM Shared online:  https://pastebin.com/LT5XESs0
  18. REM                 https://www.facebook.com/groups/maxtom3/posts/7992261460846946/
  19. REM
  20. REM BS 11/11/2022:  Implemented filelist.txt that avoids the long delay
  21. REM                 of the previous method when starting the loop.
  22. REM     Also tested using Robocopy and discovered that the copy speed was
  23. REM     basically the same as xcopy.  It does give a nice percentage indicator
  24. REM     for each file but I felt to stick with xcopy because everyone has it.
  25. REM     If you want more speed the best thing is to use a faster USB port.
  26. REM
  27. REM BS 11/19/2023:  It will now show a summary of the past 15 recording dates
  28. REM     with the number of days back, and the number of files for that date.
  29. REM     This is shown before the user selects how many days back to begin copying.
  30. REM     You must include FolderDayQty.ps1 in the same folder as this batch file,
  31. REM     (https://pastebin.com/KwZQk3uh),
  32. REM     or you can comment out the call to powershell and let the old method run.
  33. REM
  34. REM Note: If the clock in your Maxto M3 is incorrect (like after daylight savings) you
  35. REM     should use the app to link to the camera and that should re-sync the clock.  If
  36. REM     you have already recorded video and you want to correct the time shown in the
  37. REM     file properties and the filenames (but not the overlay shown on screen) then you
  38. REM     can run a Python script I made called TimeStamp_Adjust.py.  
  39. REM     A good way to know how much your M3 clock is off is to find an image where your
  40. REM     phone screen is in view, like when you are unlocking the phone.
  41.  
  42. REM Show the name of this batch file in the command window title bar
  43. TITLE %0
  44.  
  45. REM Instead of maintaining separate files for MOVIE and PHOTO files,
  46. REM I decided to set variables so I could easily deploy updates for
  47. REM either file type.
  48. REM set media=PHOTO
  49. REM set ext=jpg
  50. set ext=mp4
  51. set media=MOVIE
  52.  
  53.  
  54. set folderpath=%~dp0
  55. set logpath="%folderpath%MaintLog.txt"
  56.  
  57. REM  Set your source and destination folders.  
  58. REM  ### You must update the following line with the drive letter of your USB reader. ###
  59. set SourceFolder=E:\CARDV\%media%
  60. set TargetFolder=%folderpath%%media%
  61.  
  62. REM ## See the "Continue:" section further down to adjust the folder name that is the root of the daily folders.
  63.  
  64. if not exist %SourceFolder% (
  65.     REM Check the F: drive if not found on E:
  66.     set SourceFolder=F:\CARDV\%media%
  67. )
  68. if not exist %SourceFolder% (
  69.     ECHO.
  70.     ECHO   WARNING:  You must have the camera connected with a folder named %SourceFolder% for this to work.
  71.     ECHO 
  72.     pause
  73.     goto :eof
  74. )
  75.  
  76. if not exist %TargetFolder% (
  77.     ECHO.
  78.     ECHO   WARNING:  You must have the backup drive connected with folder %TargetFolder% available for this to work.
  79.     ECHO 
  80.     pause
  81.     goto :eof
  82. )
  83.  
  84. TITLE %0 reading from %SourceFolder%
  85.  
  86. REM _________________________________________________________________________________________________________
  87. REM First show the the user the dates of the media currently stored on the camera.
  88.  
  89. ECHO Today is %Date%.
  90. ECHO.
  91. ECHO  Source file count per date: 
  92. REM  Count the number of files per date.
  93. REM BS 11/19/2023:  Added PowerShell script to get the number of days back each recording sessions is and limit it to 15 rows.
  94. powershell -ExecutionPolicy RemoteSigned -File FolderDayQty.ps1 %SourceFolder%
  95. goto :GetDays
  96.  
  97. REM --- Use this method to list the file count per folder without the day count for the last 10 dates.
  98. REM --- The advantage of this method is no dependency on the PowerShell script file: FolderDayQty.ps1
  99. REM  https://stackoverflow.com/a/21380484
  100. REM How to change text colors in a command prompt window:  https://stackoverflow.com/a/38617204/1898524
  101. setlocal enableextensions enabledelayedexpansion
  102. set "count=0"
  103. set "previous="
  104. set "dates=0"
  105. for /f %%f in ('dir "%SourceFolder%" /a-d /tc /o-d ^| findstr /r /c:"^[^ ]"') do (
  106.     if "!previous!"=="%%f" (
  107.         set /a "count+=1"
  108.     ) else (
  109.         if defined previous echo !previous! : !REG3XP0!>!count!
  110.         set "previous=%%f"
  111.         set "count=1"
  112.         set /a "dates+=1"
  113.     )
  114.     if "!dates!"=="11" goto :GetDays
  115. )
  116. if defined previous echo !previous! : !REG3XP0!>!count!
  117. endlocal
  118. ECHO.
  119.  
  120.  
  121. REM  Prompt the user to enter the number of days to go back from today to be included
  122. REM  in the copy.  A postive number will be converted to a negative number.
  123. :GetDays
  124. set qty=3
  125. set /p "qty=How many many days do you want to copy back from?  [%qty%] : "
  126. REM Change the entered quantity into a negative number.
  127. if %qty% GTR 0 set qty=-%qty%
  128.  
  129.  
  130. SET "startTime=%time: =0%"
  131. ECHO 
  132. REM COLOR 0A
  133. Echo ----------------------------------------------------------- >> %logpath%
  134. Echo ===] %~nx0 started %date% at %time% >> %logpath%
  135. Echo ===] %~nx0 started at %time%
  136.  
  137. REM  This section calculates a formatted date that is %qty% days ago.
  138. set date1=today
  139. set separator=/
  140. if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
  141. echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
  142. echo>>"%temp%\%~n0.vbs" d=weekday(s)
  143. echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
  144. echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
  145. echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)^&_
  146. echo>>"%temp%\%~n0.vbs"         d
  147. for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
  148. del "%temp%\%~n0.vbs"
  149. endlocal& (
  150. set "YY=%result:~0,4%"
  151. set "MM=%result:~4,2%"
  152. set "DD=%result:~6,2%"
  153. set "daynum=%result:~-1%"
  154. )
  155. set "day=%MM%%separator%%DD%%separator%%YY%"
  156. REM ^^^ If your country has a different order of date fields at the command prompt
  157. REM     then you may have to alter this formula.  In the USA it is MM/DD/YY
  158.  
  159. echo.
  160. echo Searching for new files since %day% in %SourceFolder%
  161. REM Show a count of the number of files that will be processed.
  162. xcopy /S /L %SourceFolder%\*.%ext% /d:%day% | find "File(s)" >> %logpath%
  163. xcopy /S /L %SourceFolder%\*.%ext% /d:%day% | find "File(s)"  
  164. REM echo (It may hang here for a minute before you see any action)
  165.  
  166. setlocal enableDelayedExpansion
  167. REM for /f "delims=" %%a in ('forfiles /p %SourceFolder% /d %day% /m *.%ext% /c "cmd /c echo @path"') do (
  168.     REM REM echo %%~na
  169.     REM set "fname=%%~na"
  170.     REM REM Call a routine that copies each file.
  171.     REM call :continue 
  172. REM )
  173. xcopy /S /L %SourceFolder% /d:%day% | find "File(s)" /v  > %folderpath%\filelist.txt
  174. ECHO 
  175.  
  176. sort %folderpath%\filelist.txt > %folderpath%\sortedfilelist.txt
  177.  
  178. for /f "delims=" %%a in (%folderpath%\sortedfilelist.txt) do (
  179. REM for /f "delims=" %%a in ('xcopy /S /L f:\cardv\movie /d:11/4/2022 | find "File(s)" /v') do (
  180.     REM echo %%a    "%%~na"
  181.     set "fname=%%~na"
  182.     REM pause
  183.     REM Call a routine that copies each file.
  184.     call :continue 
  185. )
  186.  
  187. REM =========================================================================================================
  188. ECHO 
  189.  
  190. REM Pause if there was an error.
  191. IF %ERRORLEVEL% NEQ 0 (
  192.     COLOR 47
  193.     ECHO ### Error running %0 >> %logpath% 
  194.     ECHO ### Error running %0
  195.     Pause
  196. )
  197.  
  198.  
  199. REM https://stackoverflow.com/a/9935540/1898524
  200. REM Get end time:
  201. SET "endTime=%time: =0%"
  202. REM Get elapsed time:
  203. SET "end=!endTime:%time:~8,1%=%%100)*100+1!"  &  set "start=!startTime:%time:~8,1%=%%100)*100+1!"
  204. SET /A "elap=((((10!end:%time:~2,1%=%%100)*60+1!%%100)-((((10!start:%time:~2,1%=%%100)*60+1!%%100), elap-=(elap>>31)*24*60*60*100"
  205. REM Convert elapsed time to HH:MM:SS:CC format:
  206. SET /A "cc=elap%%100+100,elap/=100,ss=elap%%60+100,elap/=60,mm=elap%%60+100,hh=elap/60+100"
  207. SET "elapsedTime=%hh:~1%%time:~2,1%%mm:~1%%time:~2,1%%ss:~1%%time:~8,1%%cc:~1%"
  208.  
  209. REM Delete the file list.
  210. IF EXIST %folderpath%\filelist.txt DEL %folderpath%\filelist.txt
  211. IF EXIST %folderpath%\sortedfilelist.txt DEL %folderpath%\sortedfilelist.txt
  212.                                                                            
  213.  
  214. ECHO.  
  215. ECHO ----------------------------------------------------------------------------
  216. ECHO Maxto M3 archive completed at %date% %time% in %elapsedTime%  >> %logpath%
  217. ECHO   Maxto M3 archive completed at %date% %time% in %elapsedTime%    
  218. ECHO ---------------------------------------------------------------------------- 
  219. ECHO.>> %logpath%
  220. ECHO.
  221. pause
  222. exit /b
  223.  
  224.  
  225. REM ============
  226. :continue
  227. REM ============
  228. REM This section is called for every file that needs to be copied.
  229. REM echo "%fname%" "%fname:~0,8%"
  230. set datefolder=%fname:~0,8%
  231. REM dir .\%media%\%datefolder%*
  232. REM echo if not exist .\%media%\%datefolder%* (
  233. if not exist .\%media%\%datefolder%* (
  234.     echo -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  235.     echo -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  >> %logpath%
  236.     echo Creating folder: .\%media%\%datefolder%_ >> %logpath%
  237.     echo Creating folder: .\%media%\%datefolder%_ 
  238.     md .\%media%\%datefolder%_
  239. )
  240.  
  241. REM Copy the file to the folder.   
  242. for /D %%i in ("%TargetFolder%\%datefolder%*") do (
  243.     if not exist %%i\%fname%.%ext% (
  244.         echo XCOPY /D %SourceFolder%\%fname%.%ext% %%i >> %logpath%
  245.         echo XCOPY %SourceFolder%\%fname%.%ext% to %%i
  246.         XCOPY /D "%SourceFolder%\%fname%.%ext%" "%%i" > nul
  247.         IF %ERRORLEVEL% NEQ 0 (
  248.             COLOR 47
  249.             ECHO ### Error copying %SourceFolder%\%fname%.%ext% >> %logpath%   
  250.             ECHO ### Error copying %SourceFolder%\%fname%.%ext%
  251.             Pause
  252.         )      
  253.     ) else (
  254.         ECHO %fname%.%ext% already exists in %%i                >> %logpath%
  255.         ECHO  %fname%.%ext% already exists in %%i 
  256.     )
  257.     REM pause
  258. )
  259. goto :eof
  260.  
  261.  
  262. :eof
  263. echo EOF
  264. pause
  265. exit /b
  266.  
Advertisement
Comments
  • Ben_S
    1 year (edited)
    # text 0.51 KB | 0 0
    1. If you have a Maxto M3 camera you can use this file to archive all of the media on the camera. It will create a folder for each day of recording. If you append a description to the folder name it won't disturb it if you run the batch file subsequent times.
    2.  
    3. I typically archive all of my recorded video within a few days of recording it so -3 days is the default look back.
    4.  
    5. The copy method used is not as fast as Windows Explorer, but because this can run unattended and it generates a log file, I love using it.
Add Comment
Please, Sign In to add comment
Advertisement