DDK Source Files Allot 标签: ddk测试 20080917 16:03 312人阅读 评论(0)

  1. :: DDK Source Files Allot
  2. :: 从DDK的cab中解压出来的文件没有目录层级,但每个文件的文件名中包含了该文件所应
  3. :: 处于的位置。本批处理将处理单个目录中的所有文件,解析每个文件名,将之改为正确
  4. :: 名称并放入正确位置。 经测试适用于98DDK
  5. :: Author: ZeroFire(炽火)
  6. :: ver beat0.1[20080910]

  7. @echo off
  8. setlocal enabledelayedexpansion
  9. rem mode con lines=26
  10. color 1f
  11. cls
  12. title 批量处理DDK中解压的文件名
  13. set fullpath=%~dp0
  14. set selfname=%~nx0

  15. :start
  16. set oldname=
  17. :: 遍历当前目录下的所有文件
  18. for /f "usebackq delims=" %%f in (`dir /b/a-d .`) do (
  19.   set "var=%%~nf"
  20.   for /f "tokens=1,2,3,4,5,6,7,8,9* delims=_" %%i in ("!var!"do (
  21.     call :mkdir %%f %%i %%j %%k %%l %%m %%n %%o %%p %%q
  22.   )
  23. )
  24. goto ok

  25. :: 函数mkdir按照给定参数顺序检查是否存在匹配的目录树,如果不存在则创建该目录
  26. :: 然后将文件改为正确名称后移动到正确位置
  27. :: %1是目标文件名 %2~9之后是目录树
  28. :mkdir
  29. if "%3"=="" ( goto :EOF )
  30. set shortname=%1
  31. :loop
  32. if "%3"=="" (
  33.   move "%fullpath%%1" "!shortname!"
  34.   set shortpath=%CD%
  35.   set "shortpath=!shortpath:%fullpath%=!"
  36.   echo !shortpath!/!shortname!
  37. else (
  38.   if not exist "%2" (
  39.     md "%2"
  40.   )
  41.   cd "%2"
  42.   set "shortname=!shortname:%2_=!"
  43.   shift /2
  44.   goto loop
  45. )
  46. cd %fullpath%
  47. goto :EOF

  48. :: 显示成功信息并退出
  49. :ok
  50. echo done ^^_^^
  51. pause >nul
  52. goto :EOF

原文地址:https://www.cnblogs.com/zerofire/p/7162174.html