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

$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

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值