在VB程序中通过回收站删除文件
下面图老师小编跟大家分享在VB程序中通过回收站删除文件,一起来学习下过程究竟如何进行吧!喜欢就赶紧收藏起来哦~
OptionExplicit
'删除文件的API
PrivateDeclareFunctionSHFileOperationLib"shell32.dll"Alias"SHFileOperationA"(lpFileOpAsToBin)AsLong
'清空回收站的API
PrivateDeclareFunctionSHEmptyRecycleBinLib"shell32.dll"Alias"SHEmptyRecycleBinA"(ByValhwndAsLong,ByValpszRootPathAsString,ByValdwFlagsAsLong)AsLong
PrivateTypeToBin
hwndAsLong
wFuncAsLong
pFromAsString
pToAsString
fFlagsAsInteger
fAnyOperationsAbortedAsLong
hNameMappingsAsLong
lpszProgressTitleAsLong
EndType
ConstFO_DELETE=&H3
ConstFOF_ALLOWUNDO=&H40
ConstSHERB_NORMAL=&H0
'将文件移至回收站
PrivateSubCommand1_Click()
DimGoAsToBin
DimstrFileAsString
WithCommonDialog1
.Filter="(*.bak)|*.bak"
.DialogTitle="删除文件"
.ShowOpen
strFile=.FileName
EndWith
WithGo
.wFunc=FO_DELETE
.pFrom=strFile
.fFlags=FOF_ALLOWUNDO
EndWith
SHFileOperationGo
EndSub
'清空回收站
PrivateSubCommand2_Click()
DimRetValAsLong
RetVal=SHEmptyRecycleBin(0&,vbNullString,SHERB_NORMAL)
EndSub->