Board logo

标题: [其他] 生成随机文件的bat代码求解释 [打印本页]

作者: 邹哥来了    时间: 2022-5-22 13:45     标题: 生成随机文件的bat代码求解释

请各位batchers解释一下这段代码的意思:
  1. @echo off&setlocal enabledelayedexpansion
  2. set "str=abcdefghijklmnopqrstuvwxyz0123456789"
  3. set "code=jpg txt bat exe wma mp3"
  4. md test&cd test
  5. for /l %%a in (1,1,20) do (
  6.     for /l %%b in (1,1,9) do (
  7.           set /a a=!random!%%36
  8.           call,set "var=!var!%%str:~!a!,1%%"
  9.      )
  10.     set /a b=!random!%%5+1&call :lp
  11.     set "var="
  12. )
  13. goto :eof
  14. :lp
  15. for /f "tokens=%b%" %%c in ("%code%") do echo.>!var!.%%c
复制代码
本人新手,初入论坛,在此不胜感谢
作者: flashercs    时间: 2022-5-22 14:24

  1. @echo off&setlocal enabledelayedexpansion
  2. set "str=abcdefghijklmnopqrstuvwxyz0123456789"
  3. set "code=jpg txt bat exe wma mp3"
  4. md test&cd test
  5. for /l %%a in (1,1,20) do ( REM 20次
  6.     for /l %%b in (1,1,9) do ( REM 生成9位随机文件名
  7.           set /a a=!random!%%36
  8.           call,set "var=!var!%%str:~!a!,1%%"
  9.      )
  10.     set /a b=!random!%%6+1&call :lp REM 随机后缀名
  11.     set "var="
  12. )
  13. goto :eof
  14. :lp REM 生成空白随机文件
  15. for /f "tokens=%b%" %%c in ("%code%") do echo.>!var!.%%c
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2