使用批处理文件用真实数据覆盖可移动媒体上的可用空间

时间:2018-09-17 17:31:56

标签: windows batch-file

我正在创建一个批处理文件,以用真实数据完全填充USB驱动器,SD卡,Micro SD卡等上的剩余可用空间,以防止恢复以前删除的文件。设备。

背景:我有一个简单的PNY品牌的16GB SD卡,上面装有狩猎相机拍摄的静态照片。我使用Windows 8常规删除方法删除了照片。然后,我使用了Windows 8格式功能(取消选中“快速格式”选项),该功能应该可以安全地擦除数据。接下来,我在选择的驱动器上运行DiskDigger.exe程序,它检索了每张照片。然后,我运行Privazer.exe并在SD卡上执行了3 Pass DoD覆盖。尽管如此,DiskDigger仍检索了每张照片。再尝试几次将数据复制和粘贴到卡上,然后运行安全的擦除程序以删除数据,仍然可以检索照片。我无法获取照片的唯一方法是用一个128字节的文本文件覆盖SD卡上的最后一个字节,该文本文件会重复复制直到满。重新格式化驱动器后,照片将无法恢复。

很抱歉,但很详尽,但希望每个人都知道确切的问题。

我想要什么:

  • .bat文件覆盖媒体上可用的每个字节的可用空间

  • 覆盖数据将来自同一DIR中包含的一组.txt文件

  • 一旦执行,我根本不希望.bat文件提示用户

  • 我不想将.bat文件运行到出现磁盘已满错误的地步

  • 我希望它能够处理多达64GB的可移动驱动器

我所拥有的:

  • F:恰好是我特定的USB驱动器号

  • 毫无疑问,这离高效有数百万英里之遥,但我当时正在 用一种使事情起作用的方法。一直到我 获得“达到的递归SETLOCAL限制”(但是,它已填满驱动器)

  • 我首先使用.bat文件生成每个标准大小的.txt文件 并使用我的覆盖.bat文件将它们加载到同一目录中。 看来我无法使用批处理复制大于2GB的文件。 因此,我创建了8个不同名称的2GB文本文件 至少可以覆盖16GB的SD卡。我遇到的另一个问题 是提示用户确认覆盖相同文件名的提示。一世 还没有想出如何克服相同的文件名提示。

  • 我必须放置所有SETLOCAL才可以将For语句 准确读取剩余的可用空间。没有他们, 自由空间变量在每次迭代中均保持不变。

我知道有更好的方法,但是请原谅,这就是我想要的帮助。有人可以

  • 告诉我如何正确循环播放

  • 如果可能,请告诉我如何在不提示用户的情况下强制重复文件名仍然进行复制。这样可以避免我不得不创建32个不同名称的2GB .txt文件来覆盖64GB驱动器。

  • 我知道这很基本,但是是的,我希望批量生产它。

该.bat文件应该从驱动器中读取可用空间,复制将适合该空间的最大.txt文件,重新读取可用空间,复制最大的.txt文件,依此类推...直到完全填满无需用户输入即可将驱动器减小到128字节的空间,并且不会出错。

@echo off
Set "Blank=               "
Set "GB2=     2097152000"
Set "GB1=     1048576000"
Set "MB512=      524288000"
Set "MB256=      262144000"
Set "MB128=      131072000"
Set "MB64=       65536000"
Set "MB32=       32768000"
Set "MB16=       16384000"
Set "MB8=        8192000"
Set "MB4=        4096000"
Set "MB2=        2048000"
Set "MB1=        1024000"
Set "KB512=         512000"
Set "KB256=         256000"
Set "KB128=         128000"
Set "KB64=          64000"
Set "KB32=          32000"
Set "KB16=          16000"
Set "KB8=           8000"
Set "KB4=           4000"
Set "KB2=           2000"
Set "KB1=           1000"
Set "B512=            512"
Set "B256=            256"
Set "B128=            128"
Set "TB_10= 10995116277760"

for /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
echo Current time is %mydate%:%mytime%

:Loop
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%"
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (1).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (2).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (3).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (4).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (5).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (6).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (7).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB2%" ( xcopy "c:\Batch Files\File Builder\Gigabytes2 (8).txt" F:
Echo File Copied )
setlocal
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%" 
If "%FreeSpace%" gtr "%GB1%" ( xcopy "c:\Batch Files\File Builder\Gigabytes1.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB512%" ( xcopy "c:\Batch Files\File Builder\Megabytes512.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB256%" ( xcopy "c:\Batch Files\File Builder\Megabytes256.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB128%" ( xcopy "c:\Batch Files\File Builder\Megabytes128.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB64%" ( xcopy "c:\Batch Files\File Builder\Megabytes64.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB32%" ( xcopy "c:\Batch Files\File Builder\Megabytes32.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB16%" ( xcopy "c:\Batch Files\File Builder\Megabytes16.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB8%" ( xcopy "c:\Batch Files\File Builder\Megabytes8.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB4%" ( xcopy "c:\Batch Files\File Builder\Megabytes4.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB2%" ( xcopy "c:\Batch Files\File Builder\Megabytes2.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%MB1%" ( xcopy "c:\Batch Files\File Builder\Megabytes1.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB512%" ( xcopy "c:\Batch Files\File Builder\Kilobytes512.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB256%" ( xcopy "c:\Batch Files\File Builder\Kilobytes256.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB128%" ( xcopy "c:\Batch Files\File Builder\Kilobytes128.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB64%" ( xcopy "c:\Batch Files\File Builder\Kilobytes64.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB32%" ( xcopy "c:\Batch Files\File Builder\Kilobytes32.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB16%" ( xcopy "c:\Batch Files\File Builder\Kilobytes16.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB8%" ( xcopy "c:\Batch Files\File Builder\Kilobytes8.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB4%" ( xcopy "c:\Batch Files\File Builder\Kilobytes4.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB2%" ( xcopy "c:\Batch Files\File Builder\Kilobytes2.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%KB1%" ( xcopy "c:\Batch Files\File Builder\Kilobytes1.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%B512%" ( xcopy "c:\Batch Files\File Builder\Bytes512.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%B256%" ( xcopy "c:\Batch Files\File Builder\Bytes256.txt" F:
Echo File Copied
GOTO :Loop )
If "%FreeSpace%" gtr "%B128%" ( xcopy "c:\Batch Files\File Builder\Bytes128.txt" F:
Echo File Copied )
for /f "tokens=2" %%j in ('date /t') do set enddate=%%j
set endtime=%time%
echo Beginning time was %mydate%:%mytime%
echo Ending time was %enddate%:%endtime%
pause

文件运行

1 个答案:

答案 0 :(得分:0)

我想出了一个可行的解决方案,可以完成用真实文本数据覆盖可移动媒体上的可用空间的任务。 .bat程序从头到尾在我的笔记本电脑上运行,没有用户输入或错误。

我通过USB卡适配器使用空白的16GB SD卡,再次比较了CCleaner的运行时间。

  • 我的.bat文件花了33分钟的时间才用文本数据完全填充SD卡。

  • 在“ 1次伪随机数据”上设置的CCleaner花费了32分钟。

与大型商业品牌的比较给我留下了深刻的印象。我知道这个.bat文件正在将数据写入驱动器上的每个可用空间;但是,我对1遍伪随机CCleaner所做的事情并不满意。我也可以放心,此.bat文件不会拨回家,收集用户数据或保留有关我的统计信息。这是我选择编写.bat文件而不是与他人的商业品牌一起使用的原因。没有广告,没有弹出窗口,没有隐藏的互联网连接,等等。

如果有人想实际使用该程序,我可以发布一个.bat文件的副本,该文件用于生成我的特定大小的.txt文件,这些文件用作填充数据。只是给我发消息,我会尽快与您联系。

以下是我的.bat程序。我尽我所能评论它。我仍然对缩小或精简它以提高效率的建议持开放态度。我不是专家,这就是我现在批量处理的地方。最后,时间计算不正确。我想您不能简单地从结束时间中减去开始时间。我会努力的。没错。

::  THIS BATCH FILE FILLS THE REMAINING FREE SPACE OF A DRIVE WITH PREDETERMINED
::  USER CREATED DATA FILES OF SPECIFIC BYTE LENGTHS EQUALING THE LENGTHS SHOWN
::  BELOW IN THE VARIABLE INITIALIZATIONS.  
@echo off
Set "Blank=               "
Set "GB64=    67108864000"
Set "GB32=    33554432000"   
Set "GB16=    16777216000"
Set "GB8=     8388608000"
Set "GB4=     4194304000"
Set "GB2=     2097152000"
Set "GB1=     1048576000"
Set "MB512=      524288000"
Set "MB256=      262144000"
Set "MB128=      131072000"
Set "MB64=       65536000"
Set "MB32=       32778000"
Set "MB16=       16384000"
Set "MB8=        8192000"
Set "MB4=        4096000"
Set "MB2=        2048000"
Set "MB1=        1024000"
Set "KB512=         512000"
Set "KB256=         256000"
Set "KB128=         128000"
Set "KB64=          64000"
Set "KB32=          32000"
Set "KB16=          16000"
Set "KB8=           8000"
Set "KB4=           4000"
Set "KB2=           2000"
Set "KB1=           1000"
Set "B512=            512"
Set "B256=            256"
Set "B128=            128"

::  GET THE FILE EXECUTION START TIME

set StartTime=%time%
echo Start time is %StartTime%
echo.

::  GET THE CURRENT AMOUNT OF FREE SPACE ON THE REMOVEABLE MEDIA (CHANGE DRIVE LETTER AS APPROPRIATE)

for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"

::  LIMIT THE VARIABLE TO 15 DIGITS

Set "FreeSpace=%FreeSpace:~-15%"

::  PRINT INITIAL FREE SPACE IN TERMINAL WINDOW

echo Amount of intial free space to be filled = %FreeSpace%
echo.

::  BEGIN PROCESS OF NARROWING DOWN FREE SPACE BY COPYING LARGEST FILES FIRST THEN INCREMENTALLY SMALLER ONES

If "%FreeSpace%" gtr "%GB64%" ( call :TooLarge )
If "%FreeSpace%" gtr "%GB2%" ( call :Over2MB )
If "%FreeSpace%" gtr "%GB1%" ( xcopy "c:\Batch Files\File Builder\Gigabytes1.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB512%" ( xcopy "c:\Batch Files\File Builder\Megabytes512.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB256%" ( xcopy "c:\Batch Files\File Builder\Megabytes256.txt" F:
call :ReCalculate )
If "%FreeSpace%" gtr "%MB128%" ( xcopy "c:\Batch Files\File Builder\Megabytes128.txt" F:
call :ReCalculate )
If "%FreeSpace%" gtr "%MB64%" ( xcopy "c:\Batch Files\File Builder\Megabytes64.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB32%" ( xcopy "c:\Batch Files\File Builder\Megabytes32.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB16%" ( xcopy "c:\Batch Files\File Builder\Megabytes16.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB8%" ( xcopy "c:\Batch Files\File Builder\Megabytes8.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB4%" ( xcopy "c:\Batch Files\File Builder\Megabytes4.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB2%" ( xcopy "c:\Batch Files\File Builder\Megabytes2.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%MB1%" ( xcopy "c:\Batch Files\File Builder\Megabytes1.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB512%" ( xcopy "c:\Batch Files\File Builder\Kilobytes512.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB256%" ( xcopy "c:\Batch Files\File Builder\Kilobytes256.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB128%" ( xcopy "c:\Batch Files\File Builder\Kilobytes128.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB64%" ( xcopy "c:\Batch Files\File Builder\Kilobytes64.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB32%" ( xcopy "c:\Batch Files\File Builder\Kilobytes32.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB16%" ( xcopy "c:\Batch Files\File Builder\Kilobytes16.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB8%" ( xcopy "c:\Batch Files\File Builder\Kilobytes8.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB4%" ( xcopy "c:\Batch Files\File Builder\Kilobytes4.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB2%" ( xcopy "c:\Batch Files\File Builder\Kilobytes2.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%KB1%" ( xcopy "c:\Batch Files\File Builder\Kilobytes1.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%B512%" ( xcopy "c:\Batch Files\File Builder\Bytes512.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%B256%" ( xcopy "c:\Batch Files\File Builder\Bytes256.txt" F: 
call :ReCalculate)
If "%FreeSpace%" gtr "%B128%" ( xcopy "c:\Batch Files\File Builder\Bytes128.txt" F: 
call :ReCalculate)

echo. 
echo.
echo.
echo ---------Amount of free space remaining on drive f: = %FreeSpace%----------
echo.
echo.
setlocal
set StopTime=%time%
set /a CompletionTime=%StopTime%-%StartTime%
echo Total execution time was %CompletionTime% 
echo.
echo.
pause
exit /b

::  RECALCULATE FREE SPACE AFTER EACH FILE IS COPIED

:ReCalculate

for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
goto :eof


::  PERFORM COPY OF MORE THAN ONE 2MB FILE, IF NECESSARY, BY RENAMING THE FILE TO BE COPIED
::  SO AS TO AVOID A 'FILE ALREADY EXISTS' USER PROMPT

:Over2MB

set /a Counter=Counter+1
xcopy "c:\Batch Files\File Builder\Gigabytes2 ("%Counter%").txt" F:
echo File Copied "%Counter%" times.
for /f "tokens=2" %%A in ('wmic LogicalDisk Get DeviceID^,FreeSpace ^| find /i "F:"') Do Set "FreeSpace=%Blank%%%A"
Set "FreeSpace=%FreeSpace:~-15%"
Echo FreeSpace="%FreeSpace%"
If "%FreeSpace%" gtr "%GB2%" ( goto :Over2MB ) 
goto :eof

::  INFORM USER THAT THE DRIVE SPACE EXCEEDS THE CAPABILITIES OF THIS BATCH FILE 

:TooLarge

echo.
echo.
echo This program is limited to devices 64 MB or less.
echo.
echo.
echo --------------- PROGRAM ENDED ------------------
echo.
echo.
pause
exit /b