找到了相关的帖子:
http://bbs.bathome.net/viewthread.php?tid=10715- @echo off
- if "%~1"=="" goto :eof
- setlocal enableDelayedExpansion
- cd/d %~dp1
- set List=L.lst
- cd.>%List%
- for /f "delims=" %%f in ('"dir/b/a-d "%~f1" 2>nul"')do echo="%~nx1\%%f">>%List%
- for /f "delims=" %%d in ('dir/s/b/ad "%~f1"')do (
- set D1=%%d
- set D1=!d1:%~f1\=!
- echo=.set DestinationDir=!D1!>>%List%
- for /f "delims=" %%f in ('"dir/b/a-d "%%d" 2>nul"')do echo="%%d\%%f">>%List%
- )
- makecab /f %List% /d CabinetNameTemplate="..\%~n1.CAB"
- rd/s/q disk1
- del/a/f/q setup.inf;setup.rpt;%List%
复制代码 但这个例子是拖拉目录到批处理上,即只处理单个文件夹!
例如:当前目录有一些文件及有两(或N)个文件夹:cfg 和 files
当前目录的 一些文件 忽略,将那两(或N)个文件夹的文件列表:- .set DestinationDir="cfg"
- "cfg\filename.ext"
- .set DestinationDir="files"
- "files\filename.ext"
- .set DestinationDir="files\dir"
- "files\dir\filename.ext"
- .
- .
- .
复制代码 请帮忙写个批处理,谢谢!
谢谢七哥的解答:- @echo off
- cd /d "%~dp0"
- setlocal enabledelayedexpansion
- for /f "delims=" %%e in ('dir /b /on /s /ad 2^>nul') do (
- set "str=%%e"
- set "str=!str:%cd%\=!"
- >>"%~dp0FileList.txt" echo .set DestinationDir="!str!"
- pushd "%%e"
- for /f "delims=" %%j in ('dir /b /on /a-d 2^>nul') do (
- set "str2=%%~fj"
- set "str2=!str2:%cd%\=!"
- >>"%~dp0FileList.txt" echo "!str2!"
- )
- popd
- )
- endlocal
复制代码
|