如何编写'recurrsion copy'命令?

时间:2013-07-09 15:13:45

标签: recursion batch-file copy propagation

我有一个项目,我需要证明消磁器的优点,以完全擦除标准硬盘上的所有文件痕迹。我想用重复的信息传播主题HDD,例如单个词“信息”。

我在想,通过这种方式,我可以非常快速地搜索消磁驱动器,以证明该过程的卓越性。作为我的安全要求的一部分,像dBan这样的程序比破坏媒体存储和任何检索功能的过程更不可取。消磁器可以使用的环境,如果证明它的完整性,也会限制存储介质的物理破坏。

我想创建的.bat文件应包含一个递归,该递归会影响正在复制的文件的大小,以便逐步增加数据传输量,从而减少填充驱动器的时间。


我已经使用了以下内容,到目前为止,该过程在非常(相对)短暂的时间后会慢慢爬行。我已经尝试在ERRORLEVEL之前和之后使用'%',并且似乎在%符号中程序在过程的早期失败。有人有主意吗?这是我一直在使用的脚本以及我正在尝试此过程的计算机的规格:

P4,1GB Ram,2.8GHz

echo off 
Rem Setting home folder 
C:
Rem Setting Home folder again 
cd\


:copy repeat

rem Using date and time so it formats the file IT_20130708_Time in hours minutes and milliseconds

set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
COPY "IT.txt" "C:\testcopy\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy2\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy3\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy4\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy5\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy6\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy7\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy8\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy9\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"
COPY "IT.txt" "C:\testcopy10\IT_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%%RANDOM%.txt"


rem if it Does not error GOTO the start aka :copy repeat

IF ERRORLEVEL ==0 GOTO copy repeat

rem end this file if error 

goto end

:end

上述意图是即使复制操作失败,也要继续复制下一组文件。此外,该过程需要在尽可能短的时间内完成。我衷心感谢所有的建议,感谢您的时间和考虑。

1 个答案:

答案 0 :(得分:0)

你会发现的一个问题(FAT32,myabe NTFS)是文件夹中有大量文件,创建新文件需要更长的时间。你应该看看每个说50,000个文件创建一个新文件夹。

正在复制的文件大小是一个因素,因为小文件的效率非常低 - 所以这会创建一个~27 MB的文件来复制其中重复的信息。

某些驱动器格式中存在有限数量的根目录条目,因此这会创建一个根文件夹,然后在其中创建子目录。

这可能对您有用:

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set stamp=%dt:~0,8%-%dt:~8,6%

del it.txt 2>nul
echo creating string
for /L %%a in (1,1,500) do call set var=%%var%%INFORMATION
echo creating it.txt file (45 seconds...)
for /L %%a in (1,1,5000) do (set /p =%var%>>IT.TXT <nul)

for /L %%a in (1,1,2000000000) do call :next %%a
pause
goto :EOF

:next
set folder=00000000000%1
set folder=%folder:~-10%
set folder=c:\testcopy\testcopy-%folder%
md  %folder% 2>nul
set c=0
:loop
set /a c=c+1
echo %folder%-%c%
copy it.txt %folder%\IT_%stamp%_%random%%random%%random%%random%.txt >nul
if %c% EQU 50000 goto :EOF
if not errorlevel 1 goto loop
goto :EOF