在VB程序中通过回收站删除文件
2006-02-27 11:51:30 来源:WEB开发网核心提示:在标准工程中添加一个公共对话框和两个按钮即可尝试本例:OptionExplicit'删除文件的APIPRivateDeclareFunctionSHFileOperationLib"shell32.dll"Alias"SHFileOperationA"(lpFileOpA
在标准工程中添加一个公共对话框和两个按钮即可尝试本例:
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->
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->
赞助商链接