rs369007 当前离线
列兵
@echo off&setlocal ENABLEDELAYEDEXPANSION title 清理相同的文件-code by rs369007/2014/6/20 :start set /p act_path=输入目录= if not exist "!act_path!" (echo 输入目录不存在,请重新输入&ping -w 1000 -n 2 127.1>nul 2>nul&cls&goto start) set /a var=!time:~6,-3! 2>nul set /a total=0 2>nul set /a del_num=0 2>nul set "sort=C:\WINDOWS\system32\sort.exe" for /f "delims=\" %%j in ("!act_path!") do set backup_folder="%%j\rs-backup_folder\!var!"&md !backup_folder! 2>nul set tmp=c:\tmp&rd !tmp!>nul 2>nul if not exist !tmp! (md "!tmp!">nul 2>nul) else (del /f /s /q "!tmp!">nul 2>nul) set rec_file="!backup_folder!\清理记录.txt" set /a hour=!time:~0,-9! 2>nul set /a minute=!time:~3,-6! 2>nul set /a second=!time:~6,-3! 2>nul echo.&echo 程序正在对文件进行分类,请耐心等待... ::分类获取文件列表 pushd "!act_path!" for /R %%i in (*) do ( set extension=%%~xi&set extension=!extension:~-3! echo %%~zi;%%~dpnxi;%%~xi;%%~ti;%%~ni>>"!tmp!\!extension!%%~zi.txt" 2>nul ) ::分类获取完成 pushd "!tmp!" ::开始比较,记录重复文件,记录复件,而不记录原件 cls&echo.&echo 开始筛选相同文件...&ping -w 1000 -n 2 127.1>nul 2>nul echo !date!!time!>!rec_file! 2>nul for /R %%i in (*) do ( set filename=%%~nxi set /a st_count=0 for /f "tokens=1-5 delims=;" %%j in (!filename!) do ( set /a st_count+=1 if !st_count! NEQ !del_num! ( set filesize=%%j set filetime=%%m set in_filename=%%n set fullpath=%%k set /a nd_count=0 echo %%k 2>nul for /f "tokens=1-5 delims=;" %%j in (!filename!) do ( set /a nd_count+=1 if !nd_count! GTR !st_count! ( if "!filesize!"=="%%j" ( if "!filetime!"=="%%m" ( echo !in_filename!>tmp 2>nul (findstr /C:"%%n" tmp>nul 2>nul&&(echo !fullpath!;!filesize!>>!rec_file! 2>nul))||(echo %%k;%%j>>!rec_file! 2>nul) set /a del_num=!nd_count! ) ) ) ) ) ) ) pushd !backup_folder! cls&echo.&echo 开始删除相同文件:&ping -w 1000 -n 2 127.1>nul 2>nul if exist 清理记录.txt ( for /f "skip=1 tokens=1-2 delims=;" %%j in (清理记录.txt) do ( copy "%%j" "!backup_folder!">nul 2>nul del /f /s /q "%%j" set /a total+=%%k ) ) else ( echo 没有发现相同的文件。) echo.&echo (存放在!rec_file!) 2>nul&echo. set /a total=!total!/1024 set /a total=!total!/1024 echo 一共帮助你清理!total!MB 2>nul set /a o_hour=!time:~0,-9! 2>nul set /a o_minute=!time:~3,-6! 2>nul set /a o_second=!time:~6,-3! 2>nul set /a o_hour=!o_hour!-!hour! 2>nul set /a o_minute=!o_minute!-!minute! 2>nul set /a o_second=!o_second!-!second! 2>nul if !o_hour! LSS 0 (set /a o_hour=!o_hour!+24) if !o_minute! LSS 0 (set /a o_minute=!o_minute!+60&set /a o_hour=!o_hour!-1) if !o_second! LSS 0 (set /a o_second=!o_second!+60&set /a o_minute=!o_minute!-1) echo 清理耗时:!o_hour! 小时 !o_minute! 分钟 !o_second! 秒 2>nul rem 删除自身临时文件. del /f /s /q "!tmp!">nul 2>nul rem 删除空文件夹 for /f "tokens=*" %%a in ('dir /b /ad /s "!act_path!"^|!sort! /r') do rd "%%a" 2>nul rd !tmp!>nul 2>nul echo 清理结束.&pause>nul复制代码
TOP
teslawq 当前离线