Re: system() help
- Posted by ghaberek (admin) Aug 15, 2008
- 1520 views
I just posted my wrapper for SHFileOperation to The Archive.
--shfile.ew include Win32Lib.ew -- SHFileOperation Function -- http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx global constant xSHFileOperation = registerw32Function( shell32, "SHFileOperationA", {C_POINTER}, C_INT ) global constant -- possible return values for SHFileOperation DE_SAMEFILE = #71, -- The source and destination files are the same file. DE_MANYSRC1DEST = #72, -- Multiple file paths were specified in the source buffer, but only one destination file path. DE_DIFFDIR = #73, -- Rename operation was specified but the destination path is a different directory. Use the move operation instead. DE_ROOTDIR = #74, -- The source is a root directory, which cannot be moved or renamed. DE_OPCANCELLED = #75, -- The operation was cancelled by the user, or silently cancelled if the appropriate flags were supplied to SHFileOperation. DE_DESTSUBTREE = #76, -- The destination is a subtree of the source. DE_ACCESSDENIEDSRC = #78, -- Security settings denied access to the source. DE_PATHTOODEEP = #79, -- The source or destination path exceeded or would exceed MAX_PATH. DE_MANYDEST = #7A, -- The operation involved multiple destination paths, which can fail in the case of a move operation. DE_INVALIDFILES = #7C, -- The path in the source or destination or both was invalid. DE_DESTSAMETREE = #7D, -- The source and destination have the same parent folder. DE_FLDDESTISFILE = #7E, -- The destination path is an existing file. DE_FILEDESTISFLD = #80, -- The destination path is an existing folder. DE_FILENAMETOOLONG = #81, -- The name of the file exceeds MAX_PATH. DE_DEST_IS_CDROM = #82, -- The destination is a read-only CD-ROM, possibly unformatted. DE_DEST_IS_DVD = #83, -- The destination is a read-only DVD, possibly unformatted. DE_DEST_IS_CDRECORD = #84, -- The destination is a writable CD-ROM, possibly unformatted. DE_FILE_TOO_LARGE = #85, -- The file involved in the operation is too large for the destination media or file system. DE_SRC_IS_CDROM = #86, -- The source is a read-only CD-ROM, possibly unformatted. DE_SRC_IS_DVD = #87, -- The source is a read-only DVD, possibly unformatted. DE_SRC_IS_CDRECORD = #88, -- The source is a writable CD-ROM, possibly unformatted. DE_ERROR_MAX = #B7, -- MAX_PATH was exceeded during the operation. DE_ERROR_UNKNOWN = #402, -- An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later. ERRORONDEST = #10000 -- An unspecified error occurred on the destination. global constant -- SHFILEOPSTRUCT shfo_hwnd = w32allot( Long ), shfo_wFunc = w32allot( Long ), shfo_pFrom = w32allot( Lpsz ), shfo_pTo = w32allot( Lpsz ), shfo_fFlags = w32allot( Long ), shfo_fAnyOperationsAborted = w32allot( Long ), shfo_hNameMappings = w32allot( Ptr ), shfo_lpszProgressTitle = w32allot( Lpsz ), SIZEOF_SHFILEOPSTRUCT = w32allotted_size() global constant -- values for wFunc FO_MOVE = 1, FO_COPY = 2, FO_DELETE = 3, FO_RENAME = 4 global constant -- values for fFlags FOF_MULTIDESTFILES = 1, FOF_CONFIRMMOUSE = 2, FOF_SILENT = 4, FOF_RENAMEONCOLLISION = 8, FOF_NOCONFIRMATION = 16, FOF_WANTMAPPINGHANDLE = 32, FOF_ALLOWUNDO = 64, FOF_FILESONLY = 128, FOF_SIMPLEPROGRESS = 256, FOF_NOCONFIRMMKDIR = 512, FOF_NOERRORUI = 1024, FOF_NOCOPYSECURITYATTRIBS = 2048, FOF_NO_UI = w32or_all( FOF_SILENT & FOF_NOCONFIRMATION & FOF_NOERRORUI & FOF_NOCONFIRMMKDIR ) global function SHFileOperation( integer pId, atom wFunc, sequence pFrom, sequence pTo, atom fFlags, sequence szProgressTitle ) -- returns 0 if successful, -1 if the operation was canceled, or (hopefully) one of the DE_ constants above atom mset, hWnd, lpFrom, lpTo, lpszProgressTitle, shfo, ret mset = w32new_memset() if length(pFrom) and pFrom[$] != 0 then pFrom &= 0 end if if length(pTo) and pTo[$] != 0 then pTo &= 0 end if hWnd = NULL if pId then hWnd = getHandle( pId ) end if lpFrom = w32acquire_mem( mset, pFrom & 0 ) lpTo = w32acquire_mem( mset, pTo & 0 ) lpszProgressTitle = w32acquire_mem( mset, szProgressTitle & 0 ) shfo = w32acquire_mem( mset, SIZEOF_SHFILEOPSTRUCT ) w32store( shfo, shfo_hwnd, hWnd ) w32store( shfo, shfo_wFunc, wFunc ) w32store( shfo, shfo_pFrom, lpFrom ) w32store( shfo, shfo_pTo, lpTo ) w32store( shfo, shfo_fFlags, fFlags ) w32store( shfo, shfo_fAnyOperationsAborted, NULL ) w32store( shfo, shfo_hNameMappings, NULL ) w32store( shfo, shfo_lpszProgressTitle, lpszProgressTitle ) ret = w32Func( xSHFileOperation, {shfo} ) if ret = 0 then -- potentially successful, check for abort ret = w32fetch( shfo, shfo_fAnyOperationsAborted ) if ret != 0 then ret = -1 end if end if w32release_mem( mset ) return ret end function
-Greg