@goto code
from plp626@cn-dos.net
整理当前目录树下的文件(含隐藏文件)
空目录,0字节文件删除,空畸形目录删除.
支持特定文件保护功能.
:code
::按扩展名整理当前目录树下的文件(包括隐藏的)
@echo off
mode con lines=20 cols=30
title 正在分析文件...
if "%cd%"=="%HOMEDRIVE%\" exit
call :path
if "%cd:~-1%"=="\" set cd=%cd:\=%
::设定受保护目录,该目录内的所有文件,子目录将不被整理
set "protect=%cd%\zjw\"
::这定受保护文件...
set "profile=%cd%\move mp3.bat"
for /f "tokens=*" %%a in ('dir/ah/b/s 2^>nul') do attrib -h -s "%%a" >nul 2>nul
for /r %%a in (*) do (
if %%~za==0 del /a/f/q "%%a"
if not "%%a"==%0 if not "%%a"=="%profile%" (
if not "%%~dpa"=="%cd%\%%~xa_file\" if not "%%~dpa"=="%protect%" (
call:m "%%~dpa" "%%~nxa" "%%~na" "%%~xa"
)))
for /f "delims=" %%a in ('dir/ad/s/b^|findstr /e "\."') do rd "%%a.\" 2>nul
::注意只读属性的空目录
for /f "delims=" %%a in ('dir/ar/s/b 2^>nul') do attrib -r "%%a" 2>nul
for /f "tokens=*" %%b in ('dir/ad/b/s^|sort /r') do rd "%%b" 2>nul
pause
goto:eof
rem --------- subprocess ------------
:m
if exist "%~4_file\%~2" (call :rename %*) else set "n="
:m1
move "%~1%~2" "%~4_file\%~3%n%%~4" 2>nul||md "%~4_file" 2>nul&&goto:m1
goto:eof
:rename
set "n=1"
:loop
if exist "%~4_file\%~3_%n%%~4" set/a n+=1&goto loop
set "n=_%n%"&goto:eof
::备份
:path
set t=%time::=%
set r=%HOMEDRIVE%\tree
md %r% 2>nul
md "%r%\%t:~,-3%"
dir /a/b/s>>"%r%\%t:~,-3%\%t%.path"
goto:eof@echo off&setlocal enabledelayedexpansion
::抽取当前目录树下的文件.
for /f "tokens=*" %%a in ('dir/a-h/b/s 2^>nul') do attrib -h -s "%%a" 2>nul
for /r %%a in (*) do (
if exist "%%~nxa" call :re "%%~na" "%%~xa"
move "%%a" "%%~na!n!%%~xa"
)
goto :eof
:re
set "n=1"
:loop
if exist "%~1_%n%%~2" set/a n+=1&goto loop
set "n=_%n%"&goto :eof@echo off&setlocal enabledelayedexpansion
::抽取当前目录受内歌曲文件到指定路径
set "file=*.mp3 *.wma"
set "drive=%cd%\"
set "U=F:\entertainment\music\"
for /r "%drive%" %%a in (%file%) do (
if exist "!U!%%~nxa" call :re "%%~na" "%%~xa"
move "%%a" "!U!%%~na!n!%%~xa"
)
goto :eof
:re
set "n=1"
:loop
if exist "!U!%~1_%n%%~2" set/a n+=1&goto loop
set "n=_%n%"&goto :eof~~~~~~欢迎测试!~~~~~~
[ Last edited by plp626 on 2008-5-5 at 04:06 PM ]
