這樣的事情?
@ECHO OFF
SET destination=c:\temp\
SET source=c:\windows\system32\
SET dcount=0
SET fcount=0
SETLOCAL ENABLEDELAYEDEXPANSION
MKDIR %destination%dir%dcount%
FOR /f "tokens=*" %%f in ('DIR /b /s /a:d "%source%*"') do (
SET str=%%f
SET str=!str:%source%=!
MKDIR %destination%dir!dcount!\!str!
COPY %%f %destination%dir!dcount!\!str! 1> NUL
SET /a fcount=!fcount!+1
IF !fcount! EQU 100 (
SET fcount=0
SET /a dcount=!dcount!+1
MKDIR %destination%dir!dcount!
)
)
ECHO DONE.
顯然,源和目的將需要改變,並沒有試圖健全性檢查或從錯誤中優雅地失敗......
編輯:
第一個版本遞歸下降所有的子目錄並將它們移動到新的結構中 - 基本上破壞了它們的內部嵌套和組織。這第二個保留了嵌套在源目錄的直接子目錄內的子目錄的內部結構......做出選擇。
@ECHO OFF
SET destination=c:\temp\
SET source=c:\windows\system32\
SET dcount=0
SET fcount=0
SETLOCAL ENABLEDELAYEDEXPANSION
MKDIR %destination%dir%dcount%
FOR /f "tokens=*" %%f in ('DIR /b /a:d "%source%*"') do (
MKDIR %destination%dir!dcount!\%%f
XCOPY %source%%%f %destination%dir!dcount!\%%f /e /y
SET /a fcount=!fcount!+1
IF !fcount! EQU 100 (
SET fcount=0
SET /a dcount=!dcount!+1
MKDIR %destination%dir!dcount!
)
)
ECHO DONE.
你應該顯示一些自己的研究。 – Endoro 2013-05-08 22:42:00