刚查了一下,是Windows提供的脚本系统,跟控制台的rmdir一样的。
授人以渔,不授人以鱼。
SET DEFAULT TO "D:\HS" CLEAR ALL CLEAR DELDIR("A", .F.) CLEAR ALL INKEY(1) &&延时,删除 DELDIR.BAT 文件 DELETE FILE DELDIR.BAT RETURN *----------------------------------------------------------- * 參數:tcDir -- 當前默認路徑下的文件夾名,也可以用絕對路徑 * tlQuestion -- 是否需要確認,默認為要 *----------------------------------------------------------- PROCEDURE DELDIR(TCDIR, TLQUESTION) IF (PCOUNT() < 2) .OR. (VARTYPE(TLQUESTION) != "L") TLQUESTION = .T. ENDIF IF TLQUESTION .AND. (MESSAGEBOX("您确认删除文件夹" + TCDIR + "中的一切内容吗?", 32 + 4 + 256) != 6) RETURN ENDIF STRTOFILE("RD &tcDir /S /Q", "DELDIR.BAT") RUN /N7 DELDIR.BAT ENDPROC
m.lcSrc = 'C:\Output' m.lcTag = 'c:' && 删除时用不到,另有他用 *!* === api 函数声明及所用结构、常数 === DECLARE Long GlobalAlloc IN WIN32API Long, Long DECLARE Long GlobalFree IN WIN32API Long DECLARE Long SHFileOperation IN Shell32 String @ lpFileOp *!* --- SHFileOperation 函数使用的结构声明 --- *!* typedef struct _SHFILEOPSTRUCT{ *!* HWND hwnd; *!* UINT wFunc; *!* LPCSTR pFrom; *!* LPCSTR pTo; *!* FILEOP_FLAGS fFlags; *!* BOOL fAnyOperationsAborted; *!* LPVOID hNameMappings; *!* LPCSTR lpszProgressTitle; *!* } SHFILEOPSTRUCT *!* --- SHFileOperation 结构 wFunc 成员可取值 --- #define FO_MOVE 0x0001 #define FO_COPY 0x0002 #define FO_DELETE 0x0003 #define FO_RENAME 0x0004 *!* --- SHFileOperation 结构 fFlags 成员可取值(可组合使用) --- #define FOF_MULTIDESTFILES 0x0001 #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 #define FOF_FILESONLY 0x0080 && on *.*, do only files #define FOF_SIMPLEPROGRESS 0x0100 && means 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. *!* 申请内存,复制字符串,构造 api 函数要使用的结构体 m.lnPtr1 = GlobalAlloc(0x40, 2 + LEN(m.lcSrc)) SYS(2600, m.lnPtr1, LEN(m.lcSrc), m.lcSrc) m.lnPtr2 = GlobalAlloc(0x40, 2 ) &&+ LEN(m.lcTag) SYS(2600, m.lnPtr2, LEN(m.lcTag), m.lcTag) m.lcFileOp = ; BINTOC(0, '4rs') + BINTOC(FO_DELETE, '4rs') ; + BINTOC(m.lnPtr1, '4rs') + BINTOC(m.lnPtr2, '4rs') ; + BINTOC(BITOR(FOF_MULTIDESTFILES, FOF_ALLOWUNDO, FOF_NOERRORUI), '2rs') ; + REPLICATE(CHR(0), 1+4+4) *!* 调用 api 函数完成操作 m.lnResult = SHFileOperation(@ m.lcFileOp) *!* 释放申请的内存资源 GlobalFree(m.lnPtr1) GlobalFree(m.lnPtr2) *!* 显示操作结果 DO CASE CASE 0 == m.lnResult MESSAGEBOX('操作成功。', 64, '???') CASE 0 != CTOBIN(SUBSTR(m.lcFileOp, 19, 2), '2rs') MESSAGEBOX('用户取消了操作!', 48, '???') OTHERWISE MESSAGEBOX('操作失败!错误代码:' + TRANSFORM(m.lnResult), 16, '???') ENDCASE