我想用vb中做一个定点清空硬盘.
  能把达到format的效果(能删除系统文件、隐藏文件),各位请帮一下好吗?
我用的是:
 Delete 方法   
 描述
 删除一个指定的文件或文件夹。
 语法
 object.Delete force
不行呀.

解决方案 »

  1.   

    dir() 和 kill 并用看看。  
    dir来找文件和文件夹,相当于枚举, 找到的就kill掉。
      

  2.   


    Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As LongPrivate Sub Command1_Click()
        '枚举当前所有Directory
        sDirectory = Dir("c:\*.*", vbDirectory)
        Do While Len(sDirectory) > 0
            sDirectory = Dir
            Debug.Print sDirectory
           ' 删除目录(及下面所有文件及目录)
           ' RemoveDirectory sDirectory
        Loop
        '枚举当前所有File
        sFile = Dir("c:\*.*", vbDirectory)
        Do While Len(sFile) > 0
            sFile = Dir
            Debug.Print sFile
            ' 删除文件
            'kill sFile
        LoopEnd Sub
      

  3.   


    Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As LongPrivate Sub Command1_Click()
        '枚举当前所有Directory
        sDirectory = Dir("d:\*.*", vbDirectory)
        Do While Len(sDirectory) > 0
            sDirectory = Dir
            Debug.Print sDirectory
           ' 删除目录(及下面所有文件及目录)
           ' RemoveDirectory sDirectory
        Loop
        '枚举当前所有File
        sFile = Dir("d:\*.*", vbDirectory)
        Do While Len(sFile) > 0
            sFile = Dir
            Debug.Print sFile
            ' 删除文件
            'kill sFile
        LoopEnd Sub
      

  4.   

    Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As LongPrivate Sub Command1_Click()
        '枚举当前所有Directory
        sDirectory = Dir("d:\*.*", vbDirectory)
        Do While Len(sDirectory) > 0
            sDirectory = Dir
            Debug.Print sDirectory
           ' 删除目录(及下面所有文件及目录)
           ' RemoveDirectory sDirectory
        Loop
        '枚举当前所有File
        sFile = Dir("d:\*.*", vbSystem + vbNormal + vbArchive + vbHidden)
        Do While Len(sFile) > 0
            sFile = Dir
            Debug.Print sFile
            ' 删除文件
            'kill sFile
        LoopEnd Sub
      

  5.   

    Option Explicit
    '注意引用microsoft scripting runtime对象
    Private Sub Command1_Click()
        Dim FSO As New FileSystemObject
        
        Call FSO.DeleteFolder("d:\test2") '删除文件夹
        Call FSO.DeleteFile("d:\test3\123.txt") '删除文件
        Set FSO = Nothing '释放资源
    End Sub
      

  6.   

    你既然要Format就用Format啊!
    我记得Format有一个参数可以跳过询问,直接格式化,常被病毒使用的。Shell "format.com", vbHide
      

  7.   

    SHFormatDrive(SHELL32.DLL) --->FormatEx(FMIFS.DLL)Const SHFD_CAPACITY_DEFAULT = 0 ' default drive capacity
    Const SHFD_CAPACITY_360 = 3 ' 360KB, applies to 5.25" drives only
    Const SHFD_CAPACITY_720 = 5 ' 720KB, applies to 3.5" drives only
    Const SHFD_FORMAT_QUICK = 0 ' quick format
    Const SHFD_FORMAT_FULL = 1 ' full format
    Const SHFD_FORMAT_SYSONLY = 2 ' copies system files only (Win95 Only!)
    Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwndOwner As Long, ByVal iDrive As Long, ByVal iCapacity As Long, ByVal iFormatType As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'iDrive = The drive number to format. Drive A=0, B=1 (if present, otherwise C=1), and so on.
        SHFormatDrive Me.hwnd, 0, SHFD_CAPACITY_DEFAULT, SHFD_FORMAT_QUICK
    End Sub
    VOID FormatEx( PWCHAR DriveRoot,>
                      DWORD MediaFlag,
                      PWCHAR Format,
                      PWCHAR Label,
                      BOOL QuickFormat,
                      DWORD ClusterSize,
                      PFMIFSCALLBACK Callback );PFMIFSCALLBACK is:
    typedef BOOLEAN (__stdcall *PFMIFSCALLBACK)(
                      CALLBACKCOMMAND Command,
                      DWORD SubAction,
                      PVOID ActionInfo );