使用批处理文件使用实际数据覆盖可移动介质上的可用空间

问题描述 投票:0回答:1

我正在创建一个批处理文件,以完全填充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文件,并使用我的overwrite .bat文件将它们加载到同一目录中。我似乎无法使用批量复制大于2GB的文件。因此,我创建了8个不同名称的2GB文本文件,以覆盖至少16GB的SD卡。我遇到的另一个问题是提示用户确认覆盖相同的文件名。我还没弄明白如何克服同样的文件名提示。
  • 我不得不把所有的SETLOCAL只是为了让For语句准确读取剩余的可用空间。没有它们,freespace变量对于每次迭代都保持不变。

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

  • 告诉我如何正确循环这个
  • 如果可能,请告诉我如何在不提示用户的情况下强制复制文件名仍然复制。这将阻止我创建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

该文件运行

windows batch-file
1个回答
0
投票

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

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

  • 我的.bat文件需要33分钟才能完全填写带有文本数据的SD卡。
  • CCleaner设置'1次传递伪随机数据'花了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
© www.soinside.com 2019 - 2024. All rights reserved.