Reply to comment
File operations with Progressbar
It's based on the late Ed Rauh's code around SHFileOperation Win API and requires his Heap allocation class. It supports wild cards and shows standard Windows progress bar.
| This is sample code. Add error handling and adjust to your requirements as necessary. |
* Copy file to different name llSuccess = FileOpWithProgressbar("H:\TEMP\tord.dbf", "H:\TMP\TEST.dbf", "Copy") * Copy with the same name llSuccess = FileOpWithProgressbar("H:\TEMP\tord.dbf", "H:\TMP\", "Copy") * Copy all dbf's llSuccess = FileOpWithProgressbar("H:\TEMP\*.dbf", "H:\TMP\", "Copy")
* FUNCTION FileOpWithProgressbar * The SHFileOperation.h is posted at the bottom of the page #INCLUDE SHFileOperation.h LPARAMETERS tcSource, tcDestination, tcAction, tlUserCanceled LOCAL lcSourceString, lcDestString, nStringBase, lcFileOpStruct, lnFlag, lnStringBase LOCAL loHeap, lcAction, lnRetCode, llCanceled, laActionList[1] DECLARE INTEGER SHFileOperation IN SHELL32.DLL STRING @ LPSHFILEOPSTRUCT * Heap allocation class SET PROCEDURE TO CLSHEAP ADDITIVE loHeap = CREATEOBJ('Heap') lcAction = UPPER(IIF( Empty( tcAction) Or VarType(tcAction) <> "C", "COPY", tcAction)) * Convert Action name into function parameter ALINES(laActionList, "MOVE,COPY", ",") lnAction = ASCAN(laActionList, lcAction) IF lnAction = 0 * Unknown action RETURN Null ENDIF lcSourceString = tcSource + CHR(0) + CHR(0) lcDestString = tcDestination + CHR(0) + CHR(0) lnStringBase = loHeap.AllocBlob(lcSourceString+lcDestString) lnFlag = FOF_NOCONFIRMATION + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI lcFileOpStruct = NumToLONG(_screen.hWnd) + ; NumToLONG(lnAction) + ; NumToLONG(lnStringBase) + ; NumToLONG(lnStringBase + LEN(lcSourceString)) + ; NumToWORD(lnFlag) + ; NumToLONG(0) + NumToLONG(0) + NumToLONG(0) lnRetCode = SHFileOperation(@lcFileOpStruct) * Did user canceled operation? tlUserCanceled= ( SUBSTR(lcFileOpStruct, 19, 4) <> NumToLONG(0) ) RETURN (lnRetCode = 0)
SHFileOperation.h * Shell File Operations #DEFINE FO_MOVE 0x0001 #DEFINE FO_COPY 0x0002 *#DEFINE FO_DELETE 0x0003 *#DEFINE FO_RENAME 0x0004 #DEFINE FOF_MULTIDESTFILES 0x0001 #DEFINE FOF_CONFIRMMOUSE 0x0002 #DEFINE FOF_SILENT 0x0004 && don't create progress/report #DEFINE FOF_RENAMEONCOLLISION 0x0008 #DEFINE FOF_NOCONFIRMATION 0x0010 && Don't prompt the user. #DEFINE FOF_WANTMAPPINGHANDLE 0x0020 && Fill in SHFILEOPSTRUCT.hNameMappings && Must be freed using SHFreeNameMappings #DEFINE FOF_ALLOWUNDO 0x0040 && DELETE - sends the file to the Recycle Bin #DEFINE FOF_FILESONLY 0x0080 && on *.*, do only files #DEFINE FOF_SIMPLEPROGRESS 0x0100 && don't show names of files #DEFINE FOF_NOCONFIRMMKDIR 0x0200 && don't confirm making any needed dirs #DEFINE FOF_NOERRORUI 0x0400 && don't put up error UI #DEFINE FOF_NOCOPYSECURITYATTRIBS 0x0800 && dont copy NT file Security Attributes #DEFINE FOF_NORECURSION 0x1000 && don't recurse into directories.
Recent comments
1 week 4 days ago
4 weeks 19 hours ago
4 weeks 23 hours ago
4 weeks 1 day ago
4 weeks 1 day ago
5 weeks 2 days ago
8 weeks 2 days ago
10 weeks 4 days ago
12 weeks 2 days ago
12 weeks 3 days ago