本帖最后由 1291500406 于 2022-3-12 21:15 编辑
- ;;;文件 和 文件夹移送至回收站
- (defun bbfile-to-recycle (path / com1 com2 file) ;;定义接口 #SUBR ..
- (vl-load-com) ;加载核心库
- (if
- (and ;and逻辑判断语句
- (setq com1(vlax-create-object "{13709620-c279-11ce-a49e-444553540000}"));判断com1接口存在
- (setq com2(vlax-create-object "{0d43fe01-f093-11cf-8940-00a0c9054228}"));判断com2接口存在
- (findfile path) ;判断文件存在性
- )
- (progn ;开始 if ture 语句
- (if
- (=(vlax-invoke-method com2 "FolderExists" path):vlax-true) ;区分文件和文件夹的标志
- (vlax-put(setq file(vlax-invoke-method com2 "GetFolder" path))"Attributes" 0);针对只读文件夹设置为可操作文件
- (vlax-put(setq file(vlax-invoke-method com2 "getfile" path)) "Attributes" 0)
- );针对只读文件设置为可操作文件
- (if(>(*(vlax-get(vlax-invoke com2 "GetDrive" (getenv "SystemDrive"))"FreeSpace")0.95);;系统盘剩余空间*95%安全裕度
- (vlax-get file "Size")) ;;文件大小
- (vl-catch-all-apply ' vlax-invoke (list ;文件进程占用问题暂未解决,被其他软件占用时安全退出语句
- (vlax-invoke com1 "NameSpace" 10)"MoveHere" path))) ;文件删除至回收站核心语句
- (vlax-release-object com1);卸载com1
- (vlax-release-object com2);卸载com2
- t
- )
- nil
- )
- )
- ;;例子
- (bbfile-to-recycle "D:\\新建文本文档.txt")
- (bbfile-to-recycle "D:\\新建文件夹")
- ;;;当前文件管理器打开的路径
- (defun bq-explorer-path(/ path com win i path)
- (if
- (and
- (not (setq path nil))
- (setq com(vlax-create-object "{13709620-C279-11CE-A49E-444553540000}"))
- (setq win(vlax-invoke com 'Windows))
- (setq i -1)
- (repeat
- (vlax-get win 'count)
- (if (=(strcase(vl-filename-base(vlax-get(setq exeobj(vla-item win (setq i (1+ i))))'FullName)))"EXPLORER")
- (setq path(vlax-get(vlax-get(vlax-get exeobj 'document)'focuseditem)'path))
- )
- )
- path
- )
- (vl-filename-directory path)
- )
- )
- (bq-explorer-path)
|