首页 > 开发 > 综合 > 正文

自己封装的一个文件目录操作用户对象

2024-07-21 02:07:01
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。
$pbexportheader$nvo_directory.sru
$pbexportcomments$目录操作类
forward
global type nvo_directory from nonvisualobject
end type
type stc_filetime from structure within nvo_directory
end type
type stc_fileopstruct from structure within nvo_directory
end type
type stc_browseinfo from structure within nvo_directory
end type
type stc_find_data from structure within nvo_directory
end type
type large_integer from structure within nvo_directory
end type
type stc_ofstruct from structure within nvo_directory
end type
type shfileopstruct from structure within nvo_directory
end type
end forward

type stc_filetime from structure
 unsignedlong  l_time
 unsignedlong  h_time
end type

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

type stc_browseinfo from structure
 long  hwndowner
 long  pidlroot
 string  pszdisplayname
 string  lpsztitle
 unsignedlong  ulflags
 unsignedlong  lpfn
 unsignedlong  lparam
 long  iimage
end type

type stc_find_data from structure
 unsignedlong  att
 stc_filetime  c_time
 stc_filetime  a_time
 stc_filetime  w_time
 unsignedlong  h_size
 unsignedlong  l_size
 unsignedlong  dwreserved0
 unsignedlong  dwreserved1
 character  cfilename[260]
 character  calternatefilename[16]
end type

type large_integer from structure
 unsignedlong  lowpart
 unsignedlong  highpart
end type

type stc_ofstruct from structure
 character  cbytes
 character  ffixeddisk
 long  nerrcode
 long  reserved1
 long  reserved2
 character  szpathname[128]
end type

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

global type nvo_directory from nonvisualobject autoinstantiate
end type

type prototypes
function ulong getcurrentdirectorya(ulong bufferlen,ref string currentdir)library "kernel32.dll"
function ulong setcurrentdirectory(ref string lppathname) library "kernel32.dll" alias for "setcurrentdirectorya"
function ulong getmodulefilenamea(long hinstmodule, ref string lpszpath, ulong cchpath) library "kernel32.dll"
function ulong gettemppath(ulong nbufferlength,ref string lpbuffer) library "kernel32.dll" alias for "gettemppatha"
function boolean createdirectorya(string lppathname,string lpsecurityattributes) library "kernel32.dll"
function boolean removedirectorya(string lppathname) library "kernel32.dll"
function ulong gettemppatha(ulong nbufferlength,ref string lpbuffer) library "kernel32.dll"
function uint getwindowsdirectorya(ref string lpbuffer,uint usize) library "kernel32.dll"
function uint getsystemdirectorya(ref string lpbuffer,uint usize) library "kernel32.dll"
function uint getdrivetypea(string lprootpathname) library "kernel32.dll"
function ulong findclose(ulong hfindfile) library "kernel32.dll"
function ulong findfirstfile(ref string lpfilename,ref stc_find_data lpfindfiledata) library "kernel32.dll" alias for "findfirstfilea"
function ulong findnextfile(ulong hfindfile,ref stc_find_data lpfindfiledata) library "kernel32.dll" alias for "findnextfilea"
function ulong setfileattributes(ref string lpfilename,ulong dwfileattributes) library "kernel32.dll" alias for "setfileattributesa"
function boolean deletefilea(ref string filename)library "kernel32.dll"
function boolean getdiskfreespacea(string lprootpathname,ref ulong lpsectorspercluster,ref ulong  lpbytespersector,ref ulong lpnumberoffreeclusters,ref ulong lpttoalnumberofclusters) library "kernel32.dll"
function boolean getvolumeinformationa(string lprootpathname,ref string lpvolumenamebuffer,ulong nvolumenamesize,ref ulong lpvolumeserialnumber,ref ulong lpmaximumcomponentlength,ref ulong lpfilesystemflags,ref string lpfilesystemnamebuffer,ulong nfilesystemnamesize) library "kernel32.dll"
function long shfileoperation( stc_fileopstruct lpfileop) library "shell32.dll" alias for  "shfileoperationa"
function long shbrowseforfolder( ref stc_browseinfo lpbi ) library "shell32.dll"
function boolean shgetpathfromidlist( long pidl, ref string pszpath  ) library "shell32.dll" alias for "shgetpathfromidlista"
function ulong wnetaddconnection(ref string lpsznetpath,ref string lpszpassword,ref string lpszlocalname) library "mpr.dll" alias for "wnetaddconnectiona"
function ulong wnetcancelconnection(ref string lpszname,boolean bforce) library "mpr.dll" alias for "wnetcancelconnectiona"
function long shformatdrive( ulong hwnd, ulong idrive, ulong icapacity, ulong itype ) library "shell32.dll"
function long myzip_adddirectory(ref string srcpath,ref string zipfile) library "myzip.dll"
function long myzip_extractfileall(ref string zipfile,ref string pathname) library "myzip.dll"
function boolean encryptfile (ref string lpfilename)library "advapi32.dll" alias for "encryptfilea"
function boolean decryptfile(ref string lpfilename, long dwreserved ) library "advapi32.dll" alias for "decryptfilea"
function boolean movefilea(ref string lpexistingfilename,ref string lpnewfilename) library "kernel32.dll"
function long getdiskfreespaceexa(ref string lprootpathname, ref large_integer lpfreebytesavailabletocaller,ref large_integer lptotalnumberofbytes, ref large_integer lptotalnumberoffreebytes) library "kernel32.dll"
function long getfileattributes (string lpfilename ) library "kernel32.dll" alias for "getfileattributesa"
function ulong filetimetodosdatetime(ref stc_filetime lpfiletime,ref long lpfatdate,ref long lpfattime) library "kernel32.dll"
function ulong dosdatetimetofiletime(ulong wfatdate,ulong wfattime,ref stc_filetime lpfiletime) library "kernel32.dll"
function long  getlogicaldrivestrings(long nbufferlength, ref blob lpbuffer )  library "kernel32.dll" alias for  "getlogicaldrivestringsa"
function long shfileoperation( ref shfileopstruct lpfileop ) library "shell32.dll" alias for "shfileoperationa"
function long rtlmovememory(ref char destination[], long source, long size) library "kernel32"
function long rtlmovememory(long destination, ref char source[], long size) library "kernel32"
function long localalloc(long flags, long bytes) library "kernel32"
function long localfree(long memhandle) library "kernel32"
end prototypes

type variables
private:
string is_subdirs[],is_subfiles[]
long il_subdirs_number,il_subfiles_number,il_directory_space=0
constant ulong fo_move  = 1
constant ulong fo_copy  = 2
constant ulong fo_delete  = 3
constant ulong fof_allowundo  = 64
constant ulong fof_filesonly  = 128 
end variables

forward prototypes
public function string of_get_directory_current ()
public function long of_set_directory_current ()
public function long of_set_directory_current (string as_dir_name)
public function string of_get_directory_app ()
public function string of_get_directory_temp ()
public function string of_get_directory_system ()
public function string of_get_directory_windows ()
public function string of_get_drive_type (string as_rootpathname)
public function string of_get_drive_cdrom ()
public function string of_directory_create_all (string as_directory)
public function boolean of_directory_delete (string as_directory)
public function long of_directory_no_recursion (string as_first_directory, string as_second_directory, ref stc_find_data as_file[])
public function long of_directory_no_recursion (string as_directory, ref stc_find_data as_file[])
public function long of_directory_dir (string as_directory, boolean no_first_dir, ref stc_find_data as_file[])
private function boolean of_set_file_attrib (string as_filename, boolean ab_readonly, boolean ab_hidden, boolean ab_system)
private function boolean of_set_file_attrib (string as_filename, unsignedlong aul_attrib)
private function boolean of_file_delete (string as_filename)
public function boolean of_drive_isavailable (string as_drive)
public function string of_get_drive_serialnumber (string as_drive)
public function string of_get_drive_volumename (string as_drive)
private function unsignedlong of_bitwiseor (unsignedlong aul_value1, unsignedlong aul_value2)
private function string of_shbrowseforfolder (long alhparent, string asprompt, long alflags)
public function string of_directory_browseforfolder (long alhparent, string asprompt)
public function string of_directory_browseforcomputer (long alhparent, string asprompt)
public function string of_directory_browseforprinter (long alhparent, string asprompt)
public function unsignedlong of_directory_netcancelconnection (ref string as_driver)
public function boolean of_drive_format (character as_drive)
private subroutine of_get_directory_subdirs (window aw_acton, string as_directory)
public function long of_get_directory_subdirs (window aw_acton, string as_directory, ref string as_subdirs[])
private subroutine of_get_directory_subfiles (window aw_acton, string as_directory)
public function long of_get_directory_subfiles (window aw_acton, string as_directory, ref string as_subfiles[])
public function long of_get_directory_capacity (window aw_window, string as_directory)
protected function long of_get_directory_usedcapacity (string as_directory)
private function unsignedlong of_bitwiseand (unsignedlong aul_value1, unsignedlong aul_value2)
private function integer of_get_last_pos (string as_string1, string as_string2, integer ai_bz)
public function long of_directory_uncompress (ref string as_documentname, ref string as_directory)
public function long of_directory_compress (ref string as_directory, ref string as_newdocument)
public function boolean of_directory_decrypt (ref string as_directory)
public function boolean of_directory_encrypt (ref string as_directory)
public function boolean of_directory_rename (ref string as_directory, ref string as_newname)
public function boolean of_directory_create (string as_directory)
public function boolean of_directory_isavailable (string as_directory)
public function unsignedlong of_directory_netaddconnection (ref string as_directory, ref string as_pass, ref string as_driver)
public function double of_get_drive_totalspace (string as_drive)
public function double of_get_drive_freespace (string as_drive)
public function double of_get_drive_usedspace (string as_drive)
public function string of_get_drive_filesystemname (string as_drive)
public function string of_get_directory_attributes (string as_directory)
public function datetime of_get_directory_createtime (string as_directory)
public function datetime of_get_directory_writetime (string as_directory)
public function datetime of_get_directory_accesstime (string as_directory)
private function long of_makechar (readonly string asstrings[], ref character acchar[])
public function string of_get_drive_list ()
private function boolean of_shfileoperation (ref shfileopstruct lpfileop)
public function boolean of_directory_copy_all (readonly string asfrom[], readonly string asto)
public function boolean of_directory_move_all (readonly string asfrom[], readonly string asto)
public function boolean of_directory_delete_all (readonly string asfrom[])
public function boolean of_directory_move (ref string as_directory1, ref string as_directory2)
end prototypes

public function string of_get_directory_current ();/*函数作用:获取当前的文件夹名称
  返回值:string    */
string ls_curdir
ulong l_buf
l_buf=256
ls_curdir=space(l_buf)
getcurrentdirectorya(l_buf,ls_curdir)
return ls_curdir
end function

public function long of_set_directory_current ();string ls_dir_name
ls_dir_name=this.of_get_directory_app()
return this.of_set_directory_current(mid(ls_dir_name,1,lastpos(ls_dir_name,"/") - 1))

end function

public function long of_set_directory_current (string as_dir_name);return setcurrentdirectory(as_dir_name)
end function

public function string of_get_directory_app ();/*函数作用:获取当前运行的应用程序文件名称
   返回值:string    */
long   ll_rc
string  ls_apppath
long   ll_apphandler
ll_apphandler = handle(getapplication())
ls_apppath = space(256)
ll_rc = getmodulefilenamea(ll_apphandler, ls_apppath, 256)
if (ll_rc = 0) then ls_apppath = ""
return ls_apppath

end function

public function string of_get_directory_temp ();/*函数作用:获取系统临时文件夹名
   返回值:string    */       
ulong nbufferlength=255
string lpbuffer
lpbuffer=fill(' ',255)
gettemppath(nbufferlength,lpbuffer)
return lpbuffer

end function

public function string of_get_directory_system ();/*函数作用:获取系统文件夹名
   返回值:string    */             
string ls_buffer
ulong ll_requiredbuffersize

ls_buffer=space(255)
ll_requiredbuffersize=getsystemdirectorya(ls_buffer,255)

if ll_requiredbuffersize=0 or ll_requiredbuffersize>255 then setnull(ls_buffer)

return ls_buffer

 

end function

public function string of_get_directory_windows ();/*函数作用:获取windows文件夹名
   返回值:string    */                        
string ls_buffer
ulong ll_requiredbuffersize

ls_buffer=space(255)
ll_requiredbuffersize=getwindowsdirectorya(ls_buffer,255)

if ll_requiredbuffersize=0 or ll_requiredbuffersize>255 then setnull(ls_buffer)

return ls_buffer
end function

public function string of_get_drive_type (string as_rootpathname);/*函数作用:获取指定的驱动器的类型
  参数:as_drive string 驱动器名
  返回值:string   */ 
string ls_drivetype
as_rootpathname=left(as_rootpathname,1)+":"
choose case getdrivetypea(as_rootpathname)
 case 2
  ls_drivetype="removable"
 case 3
  ls_drivetype="fixed"
 case 4
  ls_drivetype="remote"
 case 5
  ls_drivetype="cdrom"
 case 6
  ls_drivetype="ramdisk"
 case else
  setnull(ls_drivetype)
end choose
return ls_drivetype
end function

public function string of_get_drive_cdrom ();/*函数作用:获取光驱的驱动器名
   返回值:string    */  
integer li_i,li_start,li_end
string ls_cdroms=""
li_start=asc("a")
li_end=asc("z")
for li_i=li_start to li_end
 if of_get_drive_type(char(li_i))="cdrom" then ls_cdroms=ls_cdroms+char(li_i)
next
return ls_cdroms
end function

public function string of_directory_create_all (string as_directory);/*函数作用:建立一个新目录(包含父文件夹)
  参数: as_directory string   文件夹名称
  返回值:boolean                         */
string ls_ret,ls_path[]
int li_i,li_j,li_pos=1
ls_ret = "ok"
do while li_pos>0
 if directoryexists(as_directory) then exit
 li_i++ ; ls_path[li_i] = as_directory
 li_pos = of_get_last_pos(as_directory,"/",1)
 as_directory = left(as_directory,li_pos)
loop
for li_j = li_i to 1 step -1  //建立目录
 if 1 <> createdirectory(ls_path[li_j]) then
  ls_ret="fa" ; exit
 end if
next
return ls_ret

end function

public function boolean of_directory_delete (string as_directory);/*函数作用:删除一个目录,不能有子文件和文件夹
  参数: as_directory string   文件夹名称
  返回值:boolean                         */
return removedirectorya(as_directory)
end function

public function long of_directory_no_recursion (string as_first_directory, string as_second_directory, ref stc_find_data as_file[]);long i,j,k
stc_find_data lss_temp
string ls_swap
k=upperbound(as_file) + 1
if mid(as_first_directory,len(as_first_directory))<>"/" then
 as_first_directory=as_first_directory+"/"
end if

if mid(as_second_directory,len(as_second_directory))<>"/" and len(as_second_directory)>0 then
 as_second_directory=as_second_directory+"/"
end if

ls_swap=as_first_directory+as_second_directory+"*"

i=findfirstfile(ls_swap,lss_temp)
if i= - 1 then
 return -1
end if
j=i
do while j<>0
 if lss_temp.cfilename='.' or lss_temp.cfilename='..' or len(trim(lss_temp.cfilename))=0 then
 else
  as_file[k]=lss_temp
  as_file[k].cfilename=as_second_directory+as_file[k].cfilename
  k++
 end if
 j=findnextfile(i,lss_temp)
loop
findclose(i)
return k - 1
end function

public function long of_directory_no_recursion (string as_directory, ref stc_find_data as_file[]);long i,j,k
stc_find_data lss_temp
string ls_swap
k=upperbound(as_file) + 1

if mid(as_directory,len(as_directory))<>"/" then
 as_directory=as_directory+"/"
end if
ls_swap=as_directory+"*"
i=findfirstfile(ls_swap,lss_temp)
if i= - 1 then
 return -1
end if
j=i
do while j<>0
 if lss_temp.cfilename='.' or lss_temp.cfilename=".." or len(trim(lss_temp.cfilename))=0 then
 else
  as_file[k]=lss_temp
  as_file[k].cfilename=as_directory+as_file[k].cfilename
  k++
 end if
 j=findnextfile(i,lss_temp)
loop
findclose(i)
return k - 1


end function

public function long of_directory_dir (string as_directory, boolean no_first_dir, ref stc_find_data as_file[]);long i,j
if no_first_dir then
 if this.of_directory_no_recursion(as_directory,'',as_file)>0 then
  j=upperbound(as_file)
  for i=1 to j
   if (mod(as_file[i].att,32) - mod(as_file[i].att,16)) >0 then
    this.of_directory_no_recursion(as_directory,as_file[i].cfilename,as_file)
    j=upperbound(as_file)
   end if
  next
 end if
else
 if this.of_directory_no_recursion(as_directory,as_file)>0 then
  j=upperbound(as_file)
  for i=1 to j
   if (mod(as_file[i].att,32) - mod(as_file[i].att,16)) >0 then
    this.of_directory_no_recursion(as_file[i].cfilename,as_file)
    j=upperbound(as_file)
   end if
  next
 end if
end if
//f_shu_debug(string(j))
return j
end function

private function boolean of_set_file_attrib (string as_filename, boolean ab_readonly, boolean ab_hidden, boolean ab_system);ulong lul_attrib=0

if ab_readonly then
 lul_attrib = lul_attrib + 1
end if
if ab_hidden then
 lul_attrib = lul_attrib + 2
end if
if ab_system then
 lul_attrib = lul_attrib + 4
end if

return not setfileattributes(as_filename,lul_attrib)=0

end function

private function boolean of_set_file_attrib (string as_filename, unsignedlong aul_attrib);return not setfileattributes(as_filename,aul_attrib)=0
end function

private function boolean of_file_delete (string as_filename);/*函数作用:删除指定的文件
  参数: string  as_filename 需删除的文件名称    
  返回值:boolean    */
return deletefilea(as_filename) 

end function

public function boolean of_drive_isavailable (string as_drive);/*函数作用:判断驱动器名是否合法
  参数: string  as_drive 驱动器名称    
  返回值:boolean    */
return not isnull(of_get_drive_type(as_drive))
end function

public function string of_get_drive_serialnumber (string as_drive);/*函数作用:获取指定的驱动器的序列号
  参数:as_drive string 驱动器名
  返回值:string    */ 
string ls_volumenamebuffer
ulong ll_volumeserialnumber
ulong ll_maximumcomponentlength
ulong ll_filesystemflags
string ls_filesystemnamebuffer
as_drive=left(as_drive,1)+":"
ls_volumenamebuffer=space(20)
ls_filesystemnamebuffer=space(20)
if not getvolumeinformationa(as_drive,ls_volumenamebuffer,20,ll_volumeserialnumber,ll_maximumcomponentlength,ll_filesystemflags,ls_filesystemnamebuffer,20) then
 setnull(ll_volumeserialnumber)
end if
return string(ll_volumeserialnumber)
end function

public function string of_get_drive_volumename (string as_drive);/*函数作用:获取指定的驱动器的卷标名称
  参数:as_drive string 驱动器名
  返回值:string   */ 
string ls_volumenamebuffer
ulong ll_volumeserialnumber
ulong ll_maximumcomponentlength
ulong ll_filesystemflags
string ls_filesystemnamebuffer
as_drive=left(as_drive,1)+":"
ls_volumenamebuffer=space(20)
ls_filesystemnamebuffer=space(20)
if not getvolumeinformationa(as_drive,ls_volumenamebuffer,20,ll_volumeserialnumber,ll_maximumcomponentlength,ll_filesystemflags,ls_filesystemnamebuffer,20) then
 setnull(ls_volumenamebuffer)
end if
return ls_volumenamebuffer
end function

private function unsignedlong of_bitwiseor (unsignedlong aul_value1, unsignedlong aul_value2);/*函数作用:对两个long类型数据进行位或操作
  参数: aul_value1 unsignedlong
        aul_value2 unsignedlong
  返回值:unsignedlong                  */
unsignedlong lul_result = 0
unsignedlong  lul_multiple = 1
unsignedlong lul_bit
if isnull(aul_value1) or isnull(aul_value2) then
 setnull(lul_result)
 return lul_result
end if
do
 lul_bit = (mod (aul_value1, 2) + mod (aul_value2, 2) + 1) /2
 lul_result +=  lul_bit * lul_multiple  
 aul_value1 = aul_value1 /2
 aul_value2 = aul_value2 /2
 lul_multiple *= 2 
loop until aul_value1 = 0 and aul_value2 = 0
return lul_result

end function

private function string of_shbrowseforfolder (long alhparent, string asprompt, long alflags);constant long max_path=260
long   llidlist
stc_browseinfo lbi
string  lspath
lbi.hwndowner   = alhparent   
lbi.pidlroot   = 0      
lbi.pszdisplayname = space( max_path ) 
lbi.lpsztitle   = asprompt    
lbi.ulflags    = alflags    
lbi.lpfn     = 0      
lbi.lparam    = 0      
lbi.iimage    = 0      
llidlist = shbrowseforfolder( lbi )
if (llidlist > 0) then 
 lspath = space( max_path ) 
 if not shgetpathfromidlist( llidlist, lspath ) then  
  lspath = ""
 end if
else 
 lspath = ""
end if  
return trim(lspath)

end function

public function string of_directory_browseforfolder (long alhparent, string asprompt);/*函数作用:对获取文件夹对话框
  参数: alparent  long 父对象的对象句柄
        as_prompt  string   对话框上标签内容
  返回值:string                         */
constant long bif_returnonlyfsdirs=1
return this.of_shbrowseforfolder( alhparent, asprompt, bif_returnonlyfsdirs )
end function

public function string of_directory_browseforcomputer (long alhparent, string asprompt);/*函数作用:对获取文件夹对话框(含网上邻居)
  参数: alparent  long 父对象的对象句柄
        as_prompt string   对话框上标签内容
  返回值:string                         */
constant ulong bif_browseforcomputer = 4096
return this.of_shbrowseforfolder( alhparent, asprompt, bif_browseforcomputer )
end function

public function string of_directory_browseforprinter (long alhparent, string asprompt);/*函数作用:对获取文件夹对话框(含打印机)
  参数: alparent  long 父对象的对象句柄
        as_prompt string   对话框上标签内容
  返回值:string                         */
constant ulong bif_browseforprinter = 8192
return this.of_shbrowseforfolder( alhparent, asprompt, bif_browseforprinter )
end function

public function unsignedlong of_directory_netcancelconnection (ref string as_driver);/*函数作用:断开映射的本地驱动器
  参数: as_driver string   本地映射驱动器名称      
  返回值:unsignedlong                         */
return wnetcancelconnection(as_driver,false)
end function

public function boolean of_drive_format (character as_drive);/*函数作用:对指定驱动器进行格式化
  参数: string  as_drive 需格式化的驱动器名称    
  返回值:boolean    */
return (shformatdrive( 0, asc(upper(as_drive)) - 65, 0, 0 ) <> 0)

end function

private subroutine of_get_directory_subdirs (window aw_acton, string as_directory);long ll,li,il_subdirs
dragobject il_lsb
string is_listitem
if right(as_directory,1)<>"/" then as_directory=as_directory+"/"
aw_acton.openuserobject(il_lsb,"listbox",0,0)
il_lsb.dynamic dirlist(as_directory+"*.2345",16)
il_subdirs=il_lsb.dynamic totalitems()
for ll=1 to il_subdirs
 is_listitem=il_lsb.dynamic text(ll)
 if is_listitem="[..]" then continue
 li = upperbound(is_subdirs)
   is_subdirs[li +1]=as_directory+mid(is_listitem,2,len(is_listitem) - 2)
 of_get_directory_subdirs(aw_acton,is_subdirs[li+1])
next
aw_acton.closeuserobject(il_lsb)
destroy il_lsb

end subroutine

public function long of_get_directory_subdirs (window aw_acton, string as_directory, ref string as_subdirs[]);/*函数作用:获取指定的文件夹的子文件夹列表
  参数:aw_window window 父窗口名称
       as_directory  string 文件夹名称,需绝对路径
   as_subdirs[]  string  存储子文件夹列表的string数组
  返回值:long    */
long ll_return
of_get_directory_subdirs(aw_acton,as_directory)
as_subdirs=is_subdirs
return il_subdirs_number
end function

private subroutine of_get_directory_subfiles (window aw_acton, string as_directory);long ll,li,il_subfiles
dragobject il_lsb
string is_listitem
if right(as_directory,1)<>"/" then as_directory=as_directory+"/"
aw_acton.openuserobject(il_lsb,"listbox",0,0)
il_lsb.dynamic dirlist(as_directory+"*.*",32823)
il_subfiles=il_lsb.dynamic totalitems()
for ll=1 to il_subfiles
 is_listitem=il_lsb.dynamic text(ll)
 if mid(is_listitem,1,1)<>"[" then
   li = upperbound(is_subfiles)
     is_subfiles[li +1]=as_directory+is_listitem
   elseif is_listitem<>"[..]" then
   of_get_directory_subfiles(aw_acton,as_directory+mid(is_listitem,2,len(is_listitem) - 2))
 end if
next
il_subfiles_number=upperbound(is_subfiles)
aw_acton.closeuserobject(il_lsb)
destroy il_lsb
end subroutine

public function long of_get_directory_subfiles (window aw_acton, string as_directory, ref string as_subfiles[]);/*函数作用:获取指定的文件夹的子文件列表
  参数:aw_window window 父窗口名称
       as_directory  string 文件夹名称,需绝对路径
   as_subfiles[]  string  存储子文件列表的string数组
  返回值:long    */
long ll_return
of_get_directory_subfiles(aw_acton,as_directory)
as_subfiles=is_subfiles
return il_subfiles_number
end function

public function long of_get_directory_capacity (window aw_window, string as_directory);/*函数作用:获取指定的文件夹的实际大小
  参数:aw_window window 父窗口名称
       as_directory  string 文件夹名称,需绝对路径
  返回值:long    */
long ll_directory_length=0,ll
string ls_subfiles[]
of_get_directory_subfiles(aw_window,as_directory,ls_subfiles)
for ll=1 to upperbound(ls_subfiles)
 ll_directory_length=ll_directory_length+filelength(ls_subfiles[ll])
next
return ll_directory_length

end function

protected function long of_get_directory_usedcapacity (string as_directory);/*函数作用:获取指定的文件夹的占用空间大小
       as_directory  string 文件夹名称,需绝对路径
  返回值:long    */
constant long max_path = 260
constant long invalid_handle_value = -1
constant long file_attribute_directory =16
stc_find_data f
long hfile,hsize
if right(as_directory, 1) <> "/" then as_directory = as_directory+"/"
as_directory=as_directory
hfile = findfirstfile(as_directory, f)
if hfile = invalid_handle_value then return 0
if of_bitwiseand(f.att,file_attribute_directory) = 0 then
   il_directory_space = il_directory_space + f.l_size
end if
findclose (hfile) 
return il_directory_space


end function

private function unsignedlong of_bitwiseand (unsignedlong aul_value1, unsignedlong aul_value2);/*函数作用:对两个long类型数据进行位与操作
  参数: aul_value1 unsignedlong
        aul_value2 unsignedlong
  返回值:unsignedlong                  */
unsignedlong lul_result = 0
unsignedlong  lul_multiple = 1
unsignedlong lul_bit
if isnull(aul_value1) or isnull(aul_value2) then
 setnull(lul_result)
 return lul_result
end if
do
 lul_bit = mod (aul_value1, 2) * mod (aul_value2, 2)
 lul_result +=  lul_bit * lul_multiple  
 aul_value1 = aul_value1 /2
 aul_value2 = aul_value2 /2
 lul_multiple *= 2 
loop until aul_value1 = 0 or aul_value2 = 0
return lul_result


end function

private function integer of_get_last_pos (string as_string1, string as_string2, integer ai_bz);integer li_len,li_i
string ls_reverse
li_len = len(as_string1)
if ai_bz=0 then
 as_string1=upper(as_string1) ; as_string2=upper(as_string2)
end if
ls_reverse = reverse(as_string1)
li_i = li_len - pos(as_string1,as_string2,1)
return li_i


end function

public function long of_directory_uncompress (ref string as_documentname, ref string as_directory);/*函数作用:对压缩文件夹进行解压缩
  参数: string  as_documentname 需解压缩的文件名,绝对路径
        string  as_directory 目标文件夹,绝对路径       
  返回值:long    */
return myzip_extractfileall(as_documentname,as_directory)
end function

public function long of_directory_compress (ref string as_directory, ref string as_newdocument);/*函数作用:对文件夹进行压缩
  参数: string  as_directory 文件夹绝对路径
        string  as_newdocument 压缩后的文件名,绝对路径
  返回值:long    */
if right(as_directory,1)="/" then
 as_directory=mid(as_directory,1,len(as_directory) - 1)
end if 
return myzip_adddirectory(as_directory,as_newdocument)
end function

public function boolean of_directory_decrypt (ref string as_directory);/*函数作用:文件夹解密,只能用与win2000以上os
  参数: as_directory string   文件夹名称
  返回值:boolean                         */
if right(as_directory,1)="/" then
 as_directory=mid(as_directory,1,len(as_directory) - 1)
end if
return decryptfile(as_directory,0)
end function

public function boolean of_directory_encrypt (ref string as_directory);/*函数作用:文件夹加密,只能用与win2000以上os
  参数: as_directory string   文件夹名称
  返回值:boolean                         */
if right(as_directory,1)="/" then
 as_directory=mid(as_directory,1,len(as_directory) - 1)
end if
return encryptfile(as_directory)
end function

public function boolean of_directory_rename (ref string as_directory, ref string as_newname);/*函数作用:重命名文件夹
  参数: as_directory string   原文件夹名称,需绝对路径
        as_newname string   文件夹新名称,不需带路径
  返回值:boolean                         */
string ls_directoryname
if right(as_directory,1)="/" then
 as_directory=mid(as_directory,len(as_directory) - 1)
end if
ls_directoryname=mid(as_directory,1,lastpos(as_directory,"/"))+as_newname
return movefilea(as_directory,ls_directoryname)
end function

public function boolean of_directory_create (string as_directory);/*函数作用:建立一个新目录
  参数: as_directory1 string   文件夹名称
  返回值:boolean                         */
string ls_securityattributes
setnull(ls_securityattributes)
return createdirectorya(as_directory,ls_securityattributes)

end function

public function boolean of_directory_isavailable (string as_directory);/*函数作用:判断文件夹是否存在
  参数: as_directory string   文件夹名称
  返回值:boolean                         */
string ls_attributes
nvo_file invo_file
ls_attributes=invo_file.of_get_file_attributes(as_directory)
if isnull(ls_attributes) then return false
return pos(ls_attributes,"d")>0
end function

public function unsignedlong of_directory_netaddconnection (ref string as_directory, ref string as_pass, ref string as_driver);/*函数作用:映射网络文件夹为本地驱动器
  参数: as_directory string   文件夹名称
        as_pass string 访问口令
    as_driver   本地驱动器名称
  返回值:unsignedlong                         */
return wnetaddconnection(as_directory, as_pass, as_driver)

end function

public function double of_get_drive_totalspace (string as_drive);/*函数作用:获取指定的驱动器的空间大小
  参数:as_drive string 驱动器名
  返回值:real   */ 
double         ld_capacity
any ia_pass
if right(as_drive,1)<>":" then
 as_drive=as_drive+":"
end if
large_integer lngfreecaller,lngtotal,lngtotalfree
getdiskfreespaceexa(as_drive, lngfreecaller, lngtotal, lngtotalfree)
if lngtotal.highpart > 0 then
   ld_capacity = ( lngtotal.highpart * 1.0 * 4294967295 ) +lngtotal.lowpart
else
   ld_capacity = lngtotal.lowpart
end if
return ld_capacity

end function

public function double of_get_drive_freespace (string as_drive);/*函数作用:获取指定的驱动器的可用空间大小
  参数:as_drive string 驱动器名
  返回值:real    */  
double         ld_capacity
any ia_pass
if right(as_drive,1)<>":" then
 as_drive=as_drive+":"
end if
large_integer lngfreecaller,lngtotal,lngtotalfree
getdiskfreespaceexa(as_drive, lngfreecaller, lngtotal, lngtotalfree)
if lngtotalfree.highpart > 0 then
   ld_capacity = ( lngtotalfree.highpart * 1.0 * 4294967295 ) +lngtotalfree.lowpart
else
   ld_capacity = lngtotalfree.lowpart
end if
return ld_capacity

end function

public function double of_get_drive_usedspace (string as_drive);/*函数作用:获取指定的驱动器的已用空间大小
  参数:as_drive string 驱动器名
  返回值:double   */ 
double         ld_capacity1,ld_capacity2
any ia_pass
if right(as_drive,1)<>":" then
 as_drive=as_drive+":"
end if
large_integer lngfreecaller,lngtotal,lngtotalfree
getdiskfreespaceexa(as_drive, lngfreecaller, lngtotal, lngtotalfree)
if lngtotal.highpart > 0 then
   ld_capacity1 = ( lngtotal.highpart * 1.0 * 4294967295 ) +lngtotal.lowpart
else
   ld_capacity1 = lngtotal.lowpart
end if
if lngtotalfree.highpart > 0 then
   ld_capacity2 = ( lngtotalfree.highpart * 1.0 * 4294967295 ) +lngtotalfree.lowpart
else
   ld_capacity2 = lngtotalfree.lowpart
end if
return ld_capacity1 - ld_capacity2

end function

public function string of_get_drive_filesystemname (string as_drive);/*函数作用:获取指定的驱动器的文件系统名称
  参数:as_drive string 驱动器名
  返回值:string   */ 
string ls_volumenamebuffer
ulong ll_volumeserialnumber
ulong ll_maximumcomponentlength
ulong ll_filesystemflags
string ls_filesystemnamebuffer
if right(as_drive,1)<>"/" then
 as_drive=as_drive+"/"
end if
ls_volumenamebuffer=space(20)
ls_filesystemnamebuffer=space(20)
getvolumeinformationa(as_drive,ls_volumenamebuffer,20,ll_volumeserialnumber,ll_maximumcomponentlength,ll_filesystemflags,ls_filesystemnamebuffer,20)
return ls_filesystemnamebuffer
end function

public function string of_get_directory_attributes (string as_directory);long ll_fileattributes
string ls_fileattributes
ll_fileattributes=getfileattributes(as_directory)
if ll_fileattributes=4294967295 then
 setnull(ls_fileattributes)
else
 if mod(ll_fileattributes, 2) >  0 then ls_fileattributes += "r"
 if mod(ll_fileattributes, 4) >  1 then ls_fileattributes += "h"
 if mod(ll_fileattributes, 8) >  3 then ls_fileattributes += "s"
 if mod(ll_fileattributes,32) > 15 then ls_fileattributes += "d"
 if mod(ll_fileattributes,64) > 31 then ls_fileattributes += "a"
end if
return ls_fileattributes
end function

public function datetime of_get_directory_createtime (string as_directory);/*函数作用:获取文件夹的创建时间
  参数: as_filename string 文件名,需绝对文件路径
  返回值:datetime                 */
long ll_code
datetime ldt_filedatetime
long lul_date,lul_time
int lui_year,lui_month,lui_day,lui_hour,lui_minute,lui_second
stc_find_data ls_file
ll_code=findfirstfile(as_directory,ls_file)
findclose(ll_code)
ldt_filedatetime=datetime(ls_file.c_time)
if ll_code=-1 then
 setnull(ldt_filedatetime)
else
 filetimetodosdatetime (ls_file.c_time,lul_date,lul_time)
 lui_day=mod(lul_date,32)
 lui_month=mod(lul_date,512)/32
 if lui_month=0 then
  lui_month=1
 end if
 lui_year=lul_date/512+1980
 lui_second=mod(lul_time,32)*2
 lui_minute=mod(lul_time,2048)/32
 lui_hour=(lul_time)/2048 + 8
 if lui_hour>=24  then
  lui_hour=lui_hour - 24
  ldt_filedatetime=datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second))
 else
  ldt_filedatetime=datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second))  
 end if
end if
return ldt_filedatetime
end function

public function datetime of_get_directory_writetime (string as_directory);/*函数作用:获取文件夹的最后读写时间
  参数: as_filename string 文件名,需绝对文件路径
  返回值:datetime                 */
long ll_code
datetime ldt_filedatetime
long lul_date,lul_time
int lui_year,lui_month,lui_day,lui_hour,lui_minute,lui_second
stc_find_data ls_file
ll_code=findfirstfile(as_directory,ls_file)
findclose(ll_code)
ldt_filedatetime=datetime(ls_file.a_time)
if ll_code=-1 then
 setnull(ldt_filedatetime)
else
 filetimetodosdatetime (ls_file.a_time,lul_date,lul_time)
 lui_day=mod(lul_date,32)
 lui_month=mod(lul_date,512)/32
 if lui_month=0 then
  lui_month=1
 end if
 lui_year=lul_date/512+1980
 lui_second=mod(lul_time,32)*2
 lui_minute=mod(lul_time,2048)/32
 lui_hour=(lul_time)/2048 + 8
 if lui_hour>=24  then
  lui_hour=lui_hour - 24
  ldt_filedatetime=datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second))
 else
  ldt_filedatetime=datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second))  
 end if
end if
return ldt_filedatetime
end function

public function datetime of_get_directory_accesstime (string as_directory);/*函数作用:获取文件夹的最后访问时间
  参数: as_filename string 文件名,需绝对文件路径
  返回值:datetime                 */
long ll_code
datetime ldt_filedatetime
long lul_date,lul_time
int lui_year,lui_month,lui_day,lui_hour,lui_minute,lui_second
stc_find_data ls_file
ll_code=findfirstfile(as_directory,ls_file)
findclose(ll_code)
ldt_filedatetime=datetime(ls_file.a_time)
if ll_code=-1 then
 setnull(ldt_filedatetime)
else
 filetimetodosdatetime (ls_file.a_time,lul_date,lul_time)
 lui_day=mod(lul_date,32)
 lui_month=mod(lul_date,512)/32
 if lui_month=0 then
  lui_month=1
 end if
 lui_year=lul_date/512+1980
 lui_second=mod(lul_time,32)*2
 lui_minute=mod(lul_time,2048)/32
 lui_hour=(lul_time)/2048 + 8
 if lui_hour>=24  then
  lui_hour=lui_hour - 24
  ldt_filedatetime=datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second))
 else
  ldt_filedatetime=datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second))  
 end if
end if
return ldt_filedatetime
end function

private function long of_makechar (readonly string asstrings[], ref character acchar[]);
char  lcchar[], lcstring[]
long  llstringcount, llstringindex
long  llcharcount, llcharindex

// count number of strings in array
llstringcount = upperbound( asstrings[] )

if (llstringcount > 0) then
 // add each of the strings to the char array
 for llstringindex = 1 to llstringcount

  // get length of current string
  llcharcount = len( asstrings[llstringindex] )

  if llcharcount > 0 then

   // convert string into char array
   lcstring = asstrings[llstringindex]

   // concatenate string to existing char array
   for llcharindex = 1 to llcharcount
    lcchar[upperbound(lcchar) + 1] = lcstring[llcharindex]
   next

   // terminate each string with a null character
   lcchar[upperbound(lcchar) + 1] = char(0)
  end if
 next
 // the last element must be double-null terminated
 lcchar[upperbound(lcchar) + 1] = char(0)
end if

// set reference argument
acchar = lcchar

// return length of char array
return upperbound( lcchar )

end function

public function string of_get_drive_list ();/*函数作用:获取驱动器列表
  参数: none  
  返回值:string    */
long c,i,pos,l=255
string ls_drive
blob{255} b
c = getlogicaldrivestrings(l,ref b)
if c>0 then
 for i=1 to c
  if asc(char(blobmid(b,i,1))) <>0 then
   ls_drive = ls_drive+ char(blobmid(b,i,1))
  else
   ls_drive = ls_drive+";"
  end if
 next
end if
return ls_drive

end function

private function boolean of_shfileoperation (ref shfileopstruct lpfileop);
return ( shfileoperation(lpfileop) = 0)

end function

public function boolean of_directory_copy_all (readonly string asfrom[], readonly string asto);shfileopstruct lpfileop
char    lcfrom[]
long    lpstring
boolean   lbcopy = false

// convert array of strings into a single null-seperated char array
if this.of_makechar( asfrom[], lcfrom ) > 0 then

 // allocate memory for char array (pstring)
 lpstring = localalloc( 0, upperbound(lcfrom) )

 // copy char array into newly allocated memory
 rtlmovememory( lpstring, lcfrom, upperbound(lcfrom) )

 // populate fileoperation structure
 lpfileop.hwnd       = 0   // no parent dialog
 lpfileop.wfunc       = fo_copy // perform a copy operation
 lpfileop.pfrom       = lpstring // source files
 lpfileop.pto       = asto  // destination directory
 lpfileop.fflags      = fof_allowundo + fof_filesonly // save undo info
 lpfileop.fanyoperationsaborted = false  // this is an output var to indicate user aborted
 lpfileop.hnamemappings    = 0   // do not want old/new pathnames
 lpfileop.lpszprogresstitle   = ""   // display default message (ie. file currently being copied).

 // perform copy
 lbcopy = this.of_shfileoperation( lpfileop )

 // free allocated memory
 localfree( lpstring )
end if

// return results of copy
return lbcopy

end function
public function boolean of_directory_move_all (readonly string asfrom[], readonly string asto);shfileopstruct lpfileop
char    lcfrom[]
long    lpstring
boolean   lbmove = false

// convert array of strings into a single null-seperated char array
if this.of_makechar( asfrom[], lcfrom ) > 0 then

 // allocate memory for char array (pstring)
 lpstring = localalloc( 0, upperbound(lcfrom) )

 // copy char array into newly allocated memory
 rtlmovememory( lpstring, lcfrom, upperbound(lcfrom) )

 // populate fileoperation structure
 lpfileop.hwnd       = 0   // no parent dialog
 lpfileop.wfunc       = fo_move // perform a move operation
 lpfileop.pfrom       = lpstring // source files
 lpfileop.pto       = asto  // destination directory
 lpfileop.fflags      = fof_allowundo + fof_filesonly // save undo info
 lpfileop.fanyoperationsaborted = false  // this is an output var to indicate user aborted
 lpfileop.hnamemappings    = 0   // do not want old/new pathnames
 lpfileop.lpszprogresstitle   = ""   // display default message (ie. file currently being copied).

 // perform move
 lbmove = this.of_shfileoperation( lpfileop )

 // free allocated memory
 localfree( lpstring )
end if

// return results of move
return lbmove

end function

public function boolean of_directory_delete_all (readonly string asfrom[]);
shfileopstruct lpfileop
char    lcfrom[]
long    lpstring
boolean   lbdelete = false

// convert array of strings into a single null-seperated char array
if this.of_makechar( asfrom[], lcfrom ) > 0 then

 // allocate memory for char array (pstring)
 lpstring = localalloc( 0, upperbound(lcfrom) )

 // copy char array into newly allocated memory
 rtlmovememory( lpstring, lcfrom, upperbound(lcfrom) )

 // populate fileoperation structure
 lpfileop.hwnd       = 0   // no parent dialog
 lpfileop.wfunc       = fo_delete // perform a delete operation
 lpfileop.pfrom       = lpstring // source files
 lpfileop.pto       = ""   // not used for delete
 lpfileop.fflags      = fof_allowundo + fof_filesonly // save undo info
 lpfileop.fanyoperationsaborted = false  // this is an output var to indicate user aborted
 lpfileop.hnamemappings    = 0   // do not want old/new pathnames
 lpfileop.lpszprogresstitle   = ""   // display default message (ie. file currently being copied).

 // perform delete
 lbdelete = this.of_shfileoperation( lpfileop )

 // free allocated memory
 localfree( lpstring )
end if

// return results of delete
return lbdelete

end function

public function boolean of_directory_move (ref string as_directory1, ref string as_directory2);/*函数作用:移动文件夹
  参数: as_directory1 string   被移动文件夹名称
        as_directory2 string   目标文件夹
  返回值:boolean                         */
if right(as_directory1,1)="/" then
 as_directory1=mid(as_directory1,len(as_directory1) - 1)
end if
if right(as_directory2,1)="/" then
 as_directory2=mid(as_directory2,len(as_directory2) - 1)
end if
return movefilea(as_directory1,as_directory2)
end function

on nvo_directory.create
call super::create
triggerevent( this, "constructor" )
end on

on nvo_directory.destroy
triggerevent( this, "destructor" )
call super::destroy
end on

 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表