在线等--VB调用API删除多个文件(其中有子目录和文件)以及格式化一个指定硬盘(逻辑盘)

解决方案 »

  1.   

    删除文件和目录可以用API函数SHFileOperation
      

  2.   

    private declare function shformatdrive lib "shell32.dll"(byval hwnd as long,byval drive as long,fmtid as long,options as long) as long
    private const shfmt_id_default=&hffff&dim lret as long
    lret=shformatdrive(me.hwnd,0,shfmt_id_default,0)
    select case lret
    case -2
    msgbox "ok"
    case 
    msgbox "cannot format a read only drive"
    end select
    end sub
    请慎重使用
      

  3.   

    Public Declare Function SHFileOperation Lib "shell32.dll" Alias " SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPublic Type SHFILEOPSTRUCT
            hwnd As Long
            wFunc As Long
            pFrom As String
            pTo As String
            fFlags As Integer
            fAnyOperationsAborted As Long
            hNameMappings As Long
            lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
    End Typedim filleoperation as shfileopstruct
    dim lreturn as long
    dim stemp as string
    stemp="c:\temp.txt"
    with fileoperation
    .wfunc=FD_DELETE
    .pfrom=stemp
    .fflags=FOF_ALLOWUNDO
    end with
    lreturn=shfileoperation(fileoperation)