• 大小: 340KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签:

资源简介

类似360的强力粉碎机,C#Winform版本的文件粉碎demo

资源截图

代码片段和文件信息

//-------------------------------------------------------------------------------------
// All Rights Reserved  Copyright (C) 2015  ZTO  Ltd .
//-------------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.IO;
using System.Text.Regularexpressions;

namespace ZTO.WayBill.Utilities
{
    /// 
    /// 文件帮助类
    ///
    /// 修改纪录
    ///
    ///   2015-6-5  版本:1.0 YangHengLian 创建主键,注意命名空间的排序。
    /// 
    /// 版本:1.0
    ///
    /// 
    /// YangHengLian
    /// 2015-6-5
    /// 

    /// 

    public class FileHelper
    {
        /// 
        /// 强力粉碎文件,文件如果被打开,很难粉碎
        /// 

        /// 文件全路径
        /// 删除次数
        /// 随机数据填充文件,默认true
        /// 空白填充文件,默认false
        /// true:粉碎成功,false:粉碎失败
        public static bool KillFile(string filename int deleteCount bool randomData = true bool blanks = false)
        {
            const int bufferLength = 1024000;
            bool ret = true;
            try
            {
                using (FileStream stream = new FileStream(filename FileMode.Open FileAccess.ReadWrite FileShare.ReadWrite))
                {
                    FileInfo f = new FileInfo(filename);
                    long count = f.Length;
                    long offset = 0;
                    var rowDataBuffer = new byte[bufferLength];
                    while (count >= 0)
                    {
                        int iNumOfDataRead = stream.Read(rowDataBuffer 0 bufferLength);
                        if (iNumOfDataRead == 0)
                        {
                            break;
                        }
                        if (randomData)
                        {
                            Random randombyte = new Random();
                            randombyte.NextBytes(rowDataBuffer);
                        }
                        else if (blanks)
                        {
                            for (int i = 0; i < iNumOfDataRead; i++)
                                rowDataBuffer[i] = 0;
                        }
                        else
                        {
                            for (int i = 0; i < iNumOfDataRead; i++)
                                rowDataBuffer[i] = Convert.ToByte(Convert.ToChar(deleteCount));
                        }
                        // 写新内容到文件。
                        for (int i = 0; i < deleteCount; i++)
                        {
                            stream.Seek(offset SeekOrigin.Begin);
                            stream.Write(rowDataBuffer 0 iNumOfDataRead);
                        }
                        offset += iNumOfDataRead;
                      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        161  2015-06-05 13:06  FileKiller\app.config

     文件       3126  2009-11-22 19:43  FileKiller\BAT.bmp

     文件        766  2009-11-22 03:48  FileKiller\BAT.ICO

     文件        366  2009-11-23 00:50  FileKiller\BAT.png

     文件      35821  2009-11-22 19:09  FileKiller\bin\Release\COPYING

     文件      24576  2015-06-05 13:08  FileKiller\bin\Release\FileKiller.exe

     文件        161  2015-06-05 13:06  FileKiller\bin\Release\FileKiller.exe.config

     文件      42496  2015-06-05 13:08  FileKiller\bin\Release\FileKiller.pdb

     文件      24216  2015-06-05 13:06  FileKiller\bin\Release\FileKiller.vshost.exe

     文件        161  2015-06-05 13:06  FileKiller\bin\Release\FileKiller.vshost.exe.config

     文件        490  2012-06-06 02:06  FileKiller\bin\Release\FileKiller.vshost.exe.manifest

     文件      75070  2009-11-24 04:46  FileKiller\bin\Release\fk_scrshot1.PNG

     文件     462936  2013-01-22 23:12  FileKiller\bin\Release\handle.exe

     文件       5424  2015-06-05 13:03  FileKiller\FileHelper.cs

     文件       6315  2015-06-05 13:07  FileKiller\FileKiller.csproj

     文件        452  2014-06-27 20:58  FileKiller\FileKiller.csproj.user

     文件        909  2014-06-27 20:58  FileKiller\FileKiller.sln

    ..A..H.     25600  2014-09-02 08:59  FileKiller\FileKiller.suo

    ..A..H.     54272  2015-06-05 13:07  FileKiller\FileKiller.v12.suo

     文件       3953  2015-06-05 13:06  FileKiller\frmMain.cs

     文件      19548  2015-06-05 12:26  FileKiller\frmMain.Designer.cs

     文件       7868  2015-06-05 12:26  FileKiller\frmMain.resx

     文件       1087  2015-06-05 13:06  FileKiller\obj\Release\DesignTimeResolveAssemblyReferences.cache

     文件       7487  2015-06-05 13:06  FileKiller\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2682  2015-06-05 13:06  FileKiller\obj\Release\FileKiller.csproj.FileListAbsolute.txt

     文件        906  2015-06-05 13:08  FileKiller\obj\Release\FileKiller.csproj.GenerateResource.Cache

     文件       3250  2015-06-05 13:08  FileKiller\obj\Release\FileKiller.csprojResolveAssemblyReference.cache

     文件      24576  2015-06-05 13:08  FileKiller\obj\Release\FileKiller.exe

     文件       1332  2015-06-05 13:08  FileKiller\obj\Release\FileKiller.frmMain.resources

     文件      42496  2015-06-05 13:08  FileKiller\obj\Release\FileKiller.pdb

............此处省略18个文件信息

评论

共有 条评论

相关资源