Bat*_*man 5 directory image batch-file windows-10
我使用的是Windows,我想随机排列特定文件夹中的图像文件,而不是以特定方式对它们进行排序,有没有办法随机排列它们?
小智 6
Windows 资源管理器 (explorer.exe) 将对文件进行排序,但您告诉它如何排序。您可以按名称、日期、类型、大小等对文件进行排序。对它们进行随机排序还需要对这些过滤器之一进行随机化。
现在,根据您需要随机化文件的目的,可以更改您的问题所需的答案。例如,如果您需要的是一种随机化屏幕保护程序或幻灯片的方法,那么这不是表达您的问题的正确方法。
但是,如果您需要的只是某种方法来随机化文件夹的内容,下面是 HowToGeek 不久前发布的一些代码:
@ECHO OFF
REM Randomly renames every file in a directory.
SETLOCAL EnableExtensions EnableDelayedExpansion
REM 0 = Rename the file randomly.
REM 1 = Prepend the existing file name with randomly generated string.
SET PrependOnly=0
REM 1 = Undo changes according to the translation file.
REM This will only work if the file "__Translation.txt" is in the same folder.
REM If you delete the translaction file, you will not be able to undo the changes!
SET Undo=0
REM --------------------------------------------------------------------------
REM Do not modify anything below this line unless you know what you are doing.
REM --------------------------------------------------------------------------
SET TranslationFile=__Translation.txt
IF NOT {%Undo%}=={1} (
REM Rename files
ECHO You are about to randomly rename every file in the following folder:
ECHO %~dp0
ECHO.
ECHO A file named %TranslationFile% will be created which allows you to undo this.
ECHO Warning: If %TranslationFile% is lost/deleted, this action cannot be undone.
ECHO Type "OK" to continue.
SET /P Confirm=
IF /I NOT {!Confirm!}=={OK} (
ECHO.
ECHO Aborting.
GOTO :EOF
)
ECHO Original Name/Random Name > %TranslationFile%
ECHO ------------------------- >> %TranslationFile%
FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
IF NOT %%A==%~nx0 (
IF NOT %%A==%TranslationFile% (
SET Use=%%~xA
IF {%PrependOnly%}=={1} SET Use=_%%A
SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
ECHO %%A/!NewName!>> %TranslationFile%
RENAME "%%A" "!NewName!"
)
)
)
) ELSE (
ECHO Undo mode.
IF NOT EXIST %TranslationFile% (
ECHO Missing translation file: %TranslationFile%
PAUSE
GOTO :EOF
)
FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
DEL /F /Q %TranslationFile%
)
Run Code Online (Sandbox Code Playgroud)