Hello.
I thought of using the API function SHFileOperation() to backup folders. I made a little test program with some codefragments i found here in the forum.
When i'am looking at handles with the taskmanager, i see while the copy is in progress handles increase.
So i included the function SHFreeNameMappings(), but handles are still the same.
How can i free those handles?
Here's the testcode, built with PBCC 4.0.4
I thought of using the API function SHFileOperation() to backup folders. I made a little test program with some codefragments i found here in the forum.
When i'am looking at handles with the taskmanager, i see while the copy is in progress handles increase.
So i included the function SHFreeNameMappings(), but handles are still the same.
How can i free those handles?
Here's the testcode, built with PBCC 4.0.4
Code:
#COMPILE EXE #DIM ALL #INCLUDE "Win32API.inc" '------------------------------------------------------ FUNCTION DirDelete( BYREF fileorfolder AS STRING) AS LONG LOCAL shfo AS shfileopstruct LOCAL lResult AS LONG LOCAL ea AS LONG shfo.wfunc = %fo_delete shfo.pfrom = STRPTR(fileorfolder) shfo.fflags = %fof_noconfirmation OR %fof_noconfirmmkdir 'OR %fof_silent lResult = shfileoperation( shfo ) ea = GetLastError() IF lResult THEN FUNCTION = ea ELSE FUNCTION = lResult END IF END FUNCTION '---------------------------------------------------------------------------- FUNCTION DirCopy( BYVAL source AS STRING, BYVAL destination AS STRING ) AS LONG LOCAL shfo AS shfileopstruct LOCAL lresult AS LONG LOCAL ea AS LONG LOCAL stemp AS STRING LOCAL sourceattributes AS LONG LOCAL nMapping AS DWORD shfo.wfunc = %fo_copy 'copy not move. shfo.pfrom = STRPTR(source) shfo.pto = STRPTR(destination) shfo.fflags = %fof_noconfirmmkdir OR %fof_noconfirmation 'or %fof_silent lResult = shfileoperation(shfo) ea = GetLastError() IF lResult THEN FUNCTION = ea ELSE nMapping = shfo.hNameMappings SHFreeNameMappings( nMapping ) 'does not really help FUNCTION = lResult END IF 'set destination attributes to the same as sources sourceattributes = GETATTR(source) SETATTR destination, sourceattributes END FUNCTION '####################################################### FUNCTION PBMAIN () AS LONG LOCAL ret AS LONG LOCAL destination AS STRING LOCAL source AS STRING 'change to your needs source = "V:\VMmachines\WinXPFSC" destination = "D:\Backup\WinXPFSC" ret = DirCopy( source, destination ) STDOUT "ret="+BIN$(ret) STDOUT "now deleting destination" WAITKEY$ ret = DirDelete( destination ) STDOUT "ret="+BIN$(ret) WAITKEY$ STDOUT "copy again..." ret = DirCopy( source, destination ) STDOUT "ret="+BIN$(ret) STDOUT "now deleting destination" ret = DirDelete( destination ) STDOUT "ret="+BIN$(ret) WAITKEY$ END FUNCTION
Comment