Advertisement
Guest User

SyncSrtFileNames.cmd

a guest
Jan 18th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.68 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. pushd
  4. if "%~1" == "" (
  5.   echo Usage: SyncSrtFileNames {folder}
  6.   goto :eof
  7. )
  8. cd /d "%~1"
  9. if not errorlevel 0 (
  10.   echo Path is not accessible.
  11.   goto :eof
  12. )
  13. for %%A in (*.srt) do (
  14.   set fname=%%A
  15.   set fext=%%~xA
  16.   set processed=0
  17.   for /f "tokens=1-30 delims=." %%B in ("%%A") do (
  18.     call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J" "%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V" "%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
  19.   )
  20.   if !processed! == 0 (
  21.     for /f "tokens=1-30 delims= " %%B in ("%%A") do (
  22.       call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J" "%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V" "%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
  23.     )
  24.   )
  25. )
  26. goto :eof
  27.  
  28. :getprefix
  29. set eps=
  30. set prefix=
  31. set separator=.
  32. call :gploop %*
  33. set eps=
  34. set prefix=
  35. set "separator= "
  36. call :gploop %*
  37. goto :eof
  38.  
  39. :gploop
  40. if "%~1" == "" goto :eof
  41. set ch=%~1
  42. call :chkeps %ch:~0,1% %ch:~1,1% %ch:~2,1% %ch:~3,1% %ch:~4,1% %ch:~5,1% %ch:~6,1%
  43. if "%prefix%" == "" (
  44.   set prefix=%~1
  45. ) else (
  46.   set prefix=%prefix%%separator%%~1
  47. )
  48. if not "%eps%" == "" (
  49.   if not "%prefix%" == "" (
  50.     for %%B in ("%prefix%*") do (
  51.       if !processed! == 0 if not "%%~B" == "%fname%" (
  52.         echo dummy: ren "%fname%" "%%~nB%!fext!"
  53.         set processed=1
  54.       )
  55.     )
  56.   )
  57.   goto :eof
  58. )
  59. shift
  60. goto :gploop
  61.  
  62. :chkeps
  63. if not "%7" == "" goto :eof
  64. if /i not "%1" == "s" goto :eof
  65. set /a num=(%2*10)+%3
  66. if !num! == 0 goto :eof
  67. if /i not "%4" == "e" goto :eof
  68. set /a num=(%5*10)+%6
  69. if !num! == 0 goto :eof
  70. set eps=%ch%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement