[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [分享]批处理版undel实现数据安全删除、恢复

简单说明:undelete命令能恢复del命令删除了的文件

不足之处:对个人隐私、机密信息有不小隐患。(Microsoft处于安全考虑,这类“高危”命令几乎都精简掉了。)

优点 :undo、后悔药之功效。


吹捧的话就不说了,简言之,小巧易用。

已测试系统:Win 7 旗舰7600 + Windows XP Mode

包组成:mydel.bat、undel.bat、mdel.bat(欢迎自行转换成其他格式,如exe)
mydel.bat:删除一(多)个文件,慎用通配符[只能匹配第一个,如果存在]。
undel.bat:恢复用mydel命令删除的文件,不支持引号。
mdel.bat:mydel.bat的封装,实现带通配符的某一特征的文件类删除。(mode_del之意)

且看代码
mydel.bat
  1. @echo off & setlocal ENABLEEXTENSIONS
  2. ::Made by [D.S.T] lnxxey 21:51 2010/2/3
  3. ::暂时还不支持直接跟带有空格的路径。
  4. ::即,参数必须是一个整体。
  5. ::另外传递的参数中引号不要超过一对。
  6. if /i "%1" equ "" goto out
  7. :start
  8. if /i "%1" equ "-d" del /a /q /f \\.\d:\undel\del_backup.txt >nul 2>nul && goto ok
  9. set all=%1
  10. if /i "%all:~1,1%" equ ":" goto whole
  11. if /i "%all:~2,1%" equ ":" goto whole
  12. if exist "%cd%%1" cacls "%cd%%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%cd%%1" >nul 2>nul & icacls "%cd%%1" /grant Administrator:(F,WDAC) >nul 2>nul
  13. if /i "%cd:~-1,1%" equ "\" (
  14. dir /a-d "%cd%%1" >nul 2>nul || goto bad
  15. )
  16. if exist "%cd%\%1" cacls "%cd%\%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%cd%\%1" >nul 2>nul & icacls "%cd%\%1" /grant Administrator:(F,WDAC) >nul 2>nul
  17. if /i "%cd:~-1,1%" neq "\" (
  18. dir /a-d "%cd%\%1" >nul 2>nul || goto bad
  19. )
  20. for /f "delims= tokens=*" %%i in ('echo %1') do set name=%%~nxi& set allf=%%~fi
  21. if exist "%1" cacls "%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%1" >nul 2>nul & icacls "%1" /grant Administrator:(F,WDAC) >nul 2>nul
  22. attrib -s -r -h %1 >nul
  23. move /y "%1" d:\undel\"%name%_lnxxey" >nul 2>nul && echo %allf%已成功删除...
  24. ::copy /y "%1" d:\undel\"%name%_lnxxey" >nul
  25. ::erase /a /q /f %1 >nul 2>nul && echo %allf%已成功删除...
  26. if /i "%cd:~-1,1%" equ "\" (
  27. echo "%cd%%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
  28. ) else (
  29. echo "%cd%\%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
  30. )
  31. ::echo "%allf%"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
  32. :ok
  33. shift /1
  34. if not "%1"=="" goto start
  35. echo 操作已完成!
  36. goto out
  37. :whole
  38. dir /a-d "%1" >nul 2>nul || goto bad
  39. cacls "%1" /t /e /c /g everyone:f >nul 2>nul|| takeown /F "%1" >nul 2>nul & icacls "%1" /grant Administrator:(F,WDAC) >nul 2>nul
  40. for /f "delims= tokens=*" %%i in ('echo %1') do set name=%%~nxi& set allf=%%~fi
  41. attrib -s -r -h %1 >nul
  42. move /y "%1" d:\undel\"%name%_lnxxey" >nul 2>nul && echo %allf%已成功删除...
  43. ::copy /y "%1" d:\undel\"%name%_lnxxey" >nul
  44. ::erase /a /q /f %1 >nul 2>nul && echo %allf%已成功删除...
  45. echo "%1"#"d:\undel\%name%_lnxxey">>d:\undel\del_backup.txt
  46. goto ok
  47. :bad
  48. echo 要删除的文件不存在!
  49. shift /1
  50. if not "%1"=="" goto start
  51. :out
复制代码
undel.bat
  1. @echo off & setlocal ENABLEEXTENSIONS
  2. ::Made by [D.S.T] lnxxey 21:51 2010/2/3
  3. ::参数不要使用任何引号
  4. if /i "%1" equ "" goto out
  5. :start
  6. dir /ad d:\undel\del_backup.txt >nul 2>nul && goto **
  7. if not exist d:\undel\del_backup.txt goto fileNexist
  8. if /i "%1" equ "-d" del /a /q /f \\.\d:\undel\del_backup.txt >nul 2>nul &if not exist "d:\undel\del_backup.txt" echo 中转记录用文件已删除... & goto ok
  9. if /i "%1" equ "-l" goto list
  10. if /i "%1" equ "-a" for /f "delims=# tokens=1,2" %%i in (d:\undel\del_backup.txt) do (
  11. if /i "%%i" neq "" (
  12. move /y %%j %%i >nul 2>nul && echo 已恢复%%i
  13. ))
  14. if /i "%1" equ "-a" goto ok
  15. type d:\undel\del_backup.txt|find /i "%1" >nul 2>nul || goto bad
  16. for /f "delims=# tokens=1,2" %%i in ('type d:\undel\del_backup.txt ^|find /i "%1" 2^>nul') do (
  17. if /i "%%i" neq "" (
  18. move /y %%j %%i >nul 2>nul && echo 已恢复%%i
  19. ))
  20. goto ok
  21. :bad
  22. echo 要恢复的文件不存在或文件名错误!注意不要使用引号...
  23. :ok
  24. shift /1
  25. if not "%1"=="" goto start
  26. goto out
  27. :**
  28. set /p you=看来你是存心搞怪,是否将搞怪进行到底[Y/N]:
  29. if /i "%you%" equ "Y" echo 此次文件恢复未成功... && goto out
  30. if /i "%you%" equ "N" rd /q /s \\.\d:\undel\del_backup.txt >nul 2>nul && echo 搞怪文件夹已经放倒... && goto start
  31. echo.
  32. echo 输入有错误,请重新输入...
  33. echo.
  34. goto **
  35. :fileNexist
  36. echo 中转用文件暂时不存在,删除文件请使用mydel命令。
  37. :out
  38. echo 操作已完成!
  39. goto :eof
  40. :list
  41. >d:\undel\sort.txt sort<d:\undel\del_backup.txt
  42. copy /y d:\undel\sort.txt d:\undel\test.txt >nul 2>nul
  43. cd.>d:\undel\much.txt
  44. setlocal enabledelayedexpansion
  45. for /f "tokens=*" %%i in (d:\undel\sort.txt) do (
  46.     set first=!second!
  47.     set second=!third!
  48.     set third=%%i
  49.     call :comp_
  50. )
  51. if not ""%second%=="" if ""%second%==""%third% >>d:\undel\much.txt echo %third%
  52. findstr . d:\undel\much.txt>nul||(del /a /f /q d:\undel\much.txt & goto result)
  53. for /f "delims=# tokens=1,2" %%i in (d:\undel\much.txt) do (
  54.     set aa=%%~nxi
  55.     find /v "!aa!" d:\undel\test.txt>>d:\undel\tmp.txt
  56.     del /q /a /f d:\undel\test.txt
  57.     ren d:\undel\tmp.txt test.txt
  58. )
  59. :result
  60. type d:\undel\much.txt>>d:\undel\test.txt && del /a /q /f d:\undel\much.txt
  61. for /f "delims=# tokens=1,2" %%i in (d:\undel\test.txt) do (if exist %%j echo 文件%%i可恢复)
  62. goto ok
  63. :comp_
  64. if not ""%first%=="" (
  65.   if not ""%second%=="" (
  66.     if ""%second%==""%first% (
  67.       if not ""%second%==""%third% >>d:\undel\much.txt echo %second%
  68.     )
  69.   )
  70. )
  71. goto :eof
复制代码
mdel.bat
  1. @echo off & setlocal ENABLEEXTENSIONS
  2. :start
  3. if /i ""%1 equ "" goto out
  4. for /f "delims= tokens=*" %%i in ('echo %1') do set filedp=%%~dpi
  5. for /f "delims= tokens=*" %%i in ('dir /a-d /b %1') do @if /i "%%i" neq "" call my_del "%filedp%%%i"
  6. shift /1
  7. goto start
  8. :out
  9. echo mdel运行完成...
复制代码

实际就是用文件夹来代替类似回收站的功能,对吧。
Do All in Command Line

TOP

返回列表