ハードディスク(HDD)のデータ完全消去(チューニング)です。
昨日の問題(状況ログ表示)を修正して再度作成ました。
昨日の内容は、過去ブログの「ハードディスク(HDD)のデータ完全消去」を参照して下さい。
仕様は下記になります。
1.実行ファイルのドライブが対象
2.フォルダ階層は「日付」→「時間(時)」→「時間(分)」
3.作成ファイル名は「時間(時、分、秒、ミリ秒)」
4.作成ファイル内容は「1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ」を「10000」回ループ
5.ファイル作成「100」回単位で状況ログとしてドライブ情報表示
→ この部分を使用変更
単純にカウンターで「状況ログ表示」を制御しても良かったのですが、
効率改善も視野に入れてチューニングしました。
【サンプルプログラム(VB.Net)】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
Imports System.IO Module ModuleMain Private Const WRITE_NUMBER As Integer = 10000 Private Const WRITE_BUFFER As String = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" Private Const CONSOLE_VIEW_NUMBER As Integer = 100 Private Const FILE_SIZE As Double = 1.2 'HDDの空き容量にデータを作成 Sub Main() '実行ファイル名取得 Dim myAssemblyName As String = My.Application.Info.AssemblyName Console.WriteLine("{0} 処理開始", myAssemblyName) Try Dim myMessage As String = String.Empty '対象ドライブ名取得 Dim myDrivePath As String = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()) Dim myDriveName As String = myDrivePath.Substring(0, 1) '実行確認取得 myMessage = String.Format("{0}ドライブの空き容量にデータ作成しますか?", myDriveName) Dim myDigResult As MsgBoxResult = MsgBox(myMessage, MsgBoxStyle.YesNo, myAssemblyName) If myDigResult = MsgBoxResult.No Then Exit Try End If '対象ドライブ情報表示 Dim myFreeSpace As Long = 0 If ConsoleDriveInfo(myDriveName, myFreeSpace) = False Then Exit Try End If 'ファイル内容作成 Dim myBuffer As String = String.Empty For ii As Integer = 1 To WRITE_NUMBER myBuffer = String.Format("{0}{1}{2}", myBuffer, WRITE_BUFFER, Environment.NewLine) Next Dim myCon_View_Num As Integer = 0 Dim mySize As Long = 0 Dim myDatePath As String = String.Empty Dim myTimeHPath As String = String.Empty Dim myTimeMPath As String = String.Empty Dim myTimeFilePath As String = String.Empty Dim myConsoleView As Integer = 0 For ii As Integer = 1 To 2 If ii = 1 Then '複数実行 myCon_View_Num = CONSOLE_VIEW_NUMBER Else '単数実行 myCon_View_Num = 1 End If 'サイズ計算 mySize = WRITE_BUFFER.Count * WRITE_NUMBER * myCon_View_Num * FILE_SIZE Do While mySize < myFreeSpace '日付ディレクトリ名生成 myDatePath = Path.Combine(myDrivePath, Now.ToString("yyyyMMdd")) If Directory.Exists(myDatePath) = False Then Directory.CreateDirectory(myDatePath) End If '時間(時)ディレクトリ名生成 myTimeHPath = Path.Combine(myDatePath, Now.ToString("HH")) If Directory.Exists(myTimeHPath) = False Then Directory.CreateDirectory(myTimeHPath) End If '時間(分)ディレクトリ名生成 myTimeMPath = Path.Combine(myTimeHPath, Now.ToString("mm")) If Directory.Exists(myTimeMPath) = False Then Directory.CreateDirectory(myTimeMPath) End If '時間ファイル作成 myTimeFilePath = Path.Combine(myTimeMPath, Now.ToString("HHmmssfff") & ".txt") Try Using myFile As New IO.StreamWriter(myTimeFilePath, False, Text.Encoding.GetEncoding("shift_jis")) '書き込み myFile.WriteLine(myBuffer) End Using Catch ex As Exception Console.WriteLine(ex.Message, myAssemblyName) Exit For End Try myConsoleView = myConsoleView + 1 If myConsoleView >= myCon_View_Num Then '対象ドライブ情報表示 If ConsoleDriveInfo(myDriveName, myFreeSpace) = False Then Exit For End If myConsoleView = 0 End If Loop Next Console.WriteLine("{0} 処理終了", myAssemblyName) myMessage = String.Format("{0}ドライブの空き容量にデータ作成完了", myDriveName) MsgBox(myMessage, MsgBoxStyle.Information, myAssemblyName) Catch ex As Exception Console.WriteLine(ex.Message, myAssemblyName) Console.WriteLine("{0} 処理終了", myAssemblyName) MsgBox(ex.Message, MsgBoxStyle.Critical, myAssemblyName) End Try End Sub Private Function ConsoleDriveInfo(ByVal myDriveName As String, ByRef myFreeSpace As Long) As Boolean '初期化 ConsoleDriveInfo = False myFreeSpace = 0 '対象ドライブ情報取得 Dim myDriveInfo As New DriveInfo(myDriveName) If myDriveInfo.IsReady = False Then Exit Function End If 'サイズ取得 Dim myTotalSize As Long = myDriveInfo.TotalSize myFreeSpace = myDriveInfo.TotalFreeSpace '画面出力 Console.WriteLine(" ") Console.WriteLine("{0}ドライブのバイト数: {1,20} Byte", myDriveName, myTotalSize.ToString("#,0")) Console.WriteLine("{0}ドライブの空きバイト数:{1,20} Byte", myDriveName, myFreeSpace.ToString("#,0")) ConsoleDriveInfo = True End Function End Module |
それでは、実行して確認します。
無事納得した結果で目的(データ完全消去)は達成しました。
結果は1分毎に1G分データ消去になります。
- 投稿タグ
- ソフト