PB的文件操作能力比较弱,自带的一些函数功能太简单,一遇上些稍微复杂些的需求(如多文件删除,文件夹的删除等)并不是非常好用,所以利用windows的API来实现相应的功能就成了最好的选择,而这其中,SHFileOperation又是最好用的,其实我说的这些并不新鲜,网上也有相关的例子,但是网上现在能找到的例程都是PB10以前的,由于从PB10开始,编码从ANSI改成了UNICODE,所以在参数的传递上,以前的一些东西要稍作下改变才可以继续使用,见到有些朋友对此有疑问,特封装了一对象(PB10以后适用),免得大家重复劳动,浪费时间,而曾经尝试过类似的工作但没有成功的朋友,请注意代码中BLOB,BLOBEDIT,LENA的使用方法,希望对大家理解ansi和unicode之间的转换能有些帮助。
*******************nvo_fileoperation,用户对象,封装了文件操作的相关函数**************************************
forward
global type nvo_fileoperation from nonvisualobjectend type
type str_operation from structure within nvo_fileoperation
end type
type str_fileoperation from structure within nvo_fileoperation
end type
end forward
type str_fileoperation from structure
unsignedlong hwnd
unsignedlong wfunc
blob pfrom
blob pto
unsignedinteger fflags
unsignedlong banyoperationsaborted
unsignedlong hnamemappings
string lpszprogresstitle
end type
global type nvo_fileoperation from nonvisualobject
end type
global nvo_fileoperation nvo_fileoperation
type prototypes
//文件操作,SHFileOperation在 Vista 及以后版本中应替换为iFileOperation
Function long SHFileOperation(ref str_fileoperation lpFileOp) Library "shell32.dll" Alias FOR "SHFileOperationA;ansi"
end prototypes
type variables
Private Constant int FO_MOVE = 1 // &H1
Private Constant int FO_COPY = 2 //&H2
Private Constant int FO_DELETE =3 //&H3
Private Constant int FO_RENAME =4 //&H4
Private Constant int FOF_NOCONFIRMATION =16 //&H10
Private Constant int FOF_SILENT = 4 //&H4
Private Constant int FOF_NOERRORUI = 1024 //&H400
end variables
forward prototypes
public function integer of_delete (string as_sourcefile[], window aw_requestor, long aui_flags)
public function integer of_copy (string as_sourcefile[], string as_target, window aw_requestor, long aui_flags)
public function integer of_move (string as_sourcefile[], string as_target, window aw_requestor, long aui_flags)
public function integer of_rename (string as_sourcefile, string as_targetfile, window aw_requestor, long aui_flags)
end prototypes
public function integer of_delete (string as_sourcefile[], window aw_requestor, long aui_flags);//====================================================================
// 函数: nvo_fileoperation::of_delete
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
// string as_sourcefile[] --需要删除的文件名
// window aw_requestor --当前窗口名
// long aui_flags --UI参数(是否显示,是否与用户