如何 Shuffle JPG图像文件和重命名顺序与批处理/ Windows

a8jjtwal  于 2023-11-21  发布在  Windows
关注(0)|答案(2)|浏览(184)

我有一个520 jpg文件的图像序列命名为:

  1. 001.jpg
  2. 002.jpg
  3. .
  4. .
  5. .
  6. 520.jpg

字符串
我想用一个windows批处理脚本来打乱图像(保持相同的序列文件名)。这可能吗?

0wi1tuuw

0wi1tuuw1#

我发现这是shuffle:

  1. @ECHO OFF
  2. REM Randomly renames every file in a directory.
  3. SETLOCAL EnableExtensions EnableDelayedExpansion
  4. REM 0 = Rename the file randomly.
  5. REM 1 = Prepend the existing file name with randomly generated string.
  6. SET PrependOnly=0
  7. REM 1 = Undo changes according to the translation file.
  8. REM This will only work if the file "__Translation.txt" is in the same folder.
  9. REM If you delete the translaction file, you will not be able to undo the changes!
  10. SET Undo=0
  11. REM --------------------------------------------------------------------------
  12. REM Do not modify anything below this line unless you know what you are doing.
  13. REM --------------------------------------------------------------------------
  14. SET TranslationFile=__Translation.txt
  15. IF NOT {%Undo%}=={1} (
  16. REM Rename files
  17. ECHO You are about to randomly rename every file in the following folder:
  18. ECHO %~dp0
  19. ECHO.
  20. ECHO A file named %TranslationFile% will be created which allows you to undo this.
  21. ECHO Warning: If %TranslationFile% is lost/deleted, this action cannot be undone.
  22. ECHO Type "OK" to continue.
  23. SET /P Confirm=
  24. IF /I NOT {!Confirm!}=={OK} (
  25. ECHO.
  26. ECHO Aborting.
  27. GOTO :EOF
  28. )
  29. ECHO Original Name/Random Name > %TranslationFile%
  30. ECHO ------------------------- >> %TranslationFile%
  31. FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
  32. IF NOT %%A==%~nx0 (
  33. IF NOT %%A==%TranslationFile% (
  34. SET Use=%%~xA
  35. IF {%PrependOnly%}=={1} SET Use=_%%A
  36. SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
  37. ECHO %%A/!NewName!>> %TranslationFile%
  38. RENAME "%%A" "!NewName!"
  39. )
  40. )
  41. )
  42. ) ELSE (
  43. ECHO Undo mode.
  44. IF NOT EXIST %TranslationFile% (
  45. ECHO Missing translation file: %TranslationFile%
  46. PAUSE
  47. GOTO :EOF
  48. )
  49. FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
  50. DEL /F /Q %TranslationFile%
  51. )

字符串
这就是序列

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set /a a=0
  4. for /f "delims=" %%I in ('dir /b *.jpg') do (
  5. set "idx=00!a!"
  6. ren "%%~I" "!idx:~-3!%%~xI"
  7. set /a a += 1
  8. )


希望这会有所帮助:)

展开查看全部
q8l4jmvw

q8l4jmvw2#

这不是这个网站的工作方式。你应该提供一个代码,你有问题,我们帮你解决问题.
不过,我现在有空闲时间,所以我写了这个给你:

  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. rem Load file names in both "in" and "out" arrays
  4. set "i=0"
  5. for %%f in (*.jpg) do (
  6. set /A i+=1
  7. set "in[!i!]=%%~Nf"
  8. set "out[!i!]=%%~Nf"
  9. )
  10. rem Shuffle "in" array and rename the files in opposite "out" order
  11. for /L %%i in (%i%,-1,1) do (
  12. set /A "pos=!random! %% %%i + 1"
  13. for %%p in (!pos!) do (
  14. ren "!in[%%p]!.jpg" "!out[%%i]!.new"
  15. set "in[%%p]=!in[%%i]!"
  16. )
  17. )
  18. ren *.new *.jpg

字符串

展开查看全部

相关问题