PB调用windows api删除文件夹及其子文件夹或子文件

本文深入探讨了如何使用编程语言进行文件操作,特别关注于删除文件夹及其子文件夹或文件的过程。通过具体示例,解释了如何在代码中实现这一功能,并强调了路径构造的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建nvo_folder对象

forward
global type nvo_folder from nonvisualobject
end type
type shfileopstruct from structure within nvo_folder
end type
end forward

type shfileopstruct from structure
    long        hwnd
    unsignedlong        wfunc
    string        pfrom
    string        pto
    unsignedlong        fflags
    boolean        fanyoperationsaborted
    long        hnamemappings
    string        lpszprogresstitle
end type

global type nvo_folder from nonvisualobject autoinstantiate
end type

type prototypes
Function long SHFileOperation( Ref SHFILEOPSTRUCT lpFileOp ) Library "shell32.dll " Alias For "SHFileOperationA"
end prototypes

type variables
//   文件操作变量
Private:
constant   ulong   FO_MOVE =   1
constant   ulong   FO_COPY =   2
constant   ulong   FO_DELETE =   3
constant   ulong   FO_RENAME =   4
//   文件操作标志位
Private:
constant   ulong   FOF_MULTIDESTFILES =   1 //   0x0001
constant   ulong   FOF_CONFIRMMOUSE =   2 //   0x0002
constant   ulong   FOF_SILENT =   4 //   0x0004
constant   ulong   FOF_RENAMEONCOLLISION =   8 //   0x0008
constant   ulong   FOF_NOCONFIRMATION =   16 //   0x0010
constant   ulong   FOF_WANTMAPPINGHANDLE =   32 //   0x0020
constant   ulong   FOF_ALLOWUNDO =   64 //   0x0040
constant   ulong   FOF_FILESONLY =   128 //   0x0080
constant   ulong   FOF_SIMPLEPROGRESS =   256 //   0x0100
constant   ulong   FOF_NOCONFIRMMKDIR =   512 //   0x0200
constant   ulong   FOF_NOERRORUI =   1024 //   0x0400
end variables

forward prototypes
public function boolean of_removefolder (string as_folder)
end prototypes

public function boolean of_removefolder (string as_folder);//删除文件夹as_folder及其子文件夹或文件
SHFILEOPSTRUCT FileOp
FileOp.fFlags = FOF_NOCONFIRMATION
FileOp.hNameMappings = 0
FileOp.hwnd = 0
FileOp.lpszProgressTitle = ''
FileOp.pFrom = as_folder
FileOp.pTo = ''
FileOp.wFunc = FO_Delete
return SHFileOperation(FileOp) = 0

end function

on nvo_folder.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nvo_folder.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on



nvofolder.of_removefolder(gs_apppath+'\jpg')



jpg文件夹后增加反斜杠'\'与没有反斜杠  是有区别的。。。。。表示不解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值