1.copy file
c:
cd c:\test
dir /b /s |findstr ".*\.pdf" > c:\t.txt
for /f "delims=/" %i in (c:\t.txt) do @copy "%i" c:\Dest\
2.creat floder
cd c:\dest
dir /b /s |findstr ".*\.pdf" > c:\t2.txt
for /f "tokens=3 delims=\" %i in (c:\t2.txt) do @md "%~ni"
rem ~ni 只用文件名,不用扩展名
3.match and move file
for /f "tokens=3 delims=\" %i in (c:\t2.txt) do @move "%i" c:\Dest\"%~ni"\
rem tokens=3 提取第三个记录
rem "%~ni" 引号是去空格
完整版:
c:\test 源文件目录
c:\log 日志文件目录
c:\file 交换文件目录
c:\dest 目标文件目录
c:
cd c:\test
dir /b /s |findstr ".*\.pdf" > c:\log\pdf1.txt
dir /b /s |findstr ".*\.dxf" > c:\log\dxf1.txt
dir /b /s |findstr ".*\.dwg" > c:\log\dwg1.txt
for /f "delims=/" %%i in (c:\log\pdf1.txt) do @copy "%%i" c:\Dest\file\ /y
for /f "delims=/" %%i in (c:\log\dxf1.txt) do @copy "%%i" c:\Dest\file\ /y
for /f "delims=/" %%i in (c:\log\dwg1.txt) do @copy "%%i" c:\Dest\file\ /y
cd c:\dest\file\
dir /b /s |findstr ".*\.pdf" > c:\log\pdf2.txt
for /f "tokens=4 delims=\" %%i in (c:\log\pdf2.txt) do @md c:\dest\data\"%%~ni"
for /f "tokens=4 delims=\" %%i in (c:\log\pdf2.txt) do @move "%%i" c:\dest\data\"%%~ni"\
for /f "tokens=4 delims=\" %%i in (c:\log\pdf2.txt) do @move "%%~ni.dxf" c:\dest\data\"%%~ni"\
for /f "tokens=4 delims=\" %%i in (c:\log\pdf2.txt) do @move "%%~ni.dwg" c:\dest\data\"%%~ni"\
cd c:\dest\file\
dir /b /s |findstr ".*\.dxf" > c:\log\dxf2.txt
for /f "tokens=4 delims=\" %%i in (c:\log\dxf2.txt) do @md c:\dest\data\"%%~ni"
for /f "tokens=4 delims=\" %%i in (c:\log\dxf2.txt) do @move "%%i" c:\dest\data\"%%~ni"\
for /f "tokens=4 delims=\" %%i in (c:\log\dxf2.txt) do @move "%%~ni.dwg" c:\dest\data\"%%~ni"\
cd c:\dest\file\
dir /b /s |findstr ".*\.dwg" > c:\log\dwg2.txt
for /f "tokens=4 delims=\" %%i in (c:\log\dwg2.txt) do @md c:\dest\data\"%%~ni"
for /f "tokens=4 delims=\" %%i in (c:\log\dwg2.txt) do @move "%%i" c:\dest\data\"%%~ni"\
转载于:https://blog.51cto.com/greenp/780284