获取并设置文件属性ch
亲爱的程序员我需要一个小例程来设置文件的属性(即只读或隐藏)
据我所知,您需要使用脚本。FileSystemObject,但我还不熟悉
同一个例程应该能够读取同一个文件,并返回设置的属性
获取att的结果也可以是数字
i、 e.2仅隐藏,1仅为只读
2081=只读+存档+内容索引+压缩
亲切的问候 你想用什么编程语言? 请尝试acet file attr(ExpressTools)。 很抱歉没有具体说明lol
*lisp是一种语言 也许这会让你朝着正确的方向开始:
(defun _fileatts (file / f sfso)
(cond ((and (findfile file) (setq sfso (vlax-get-or-create-object "Scripting.FileSystemObject")))
(setq f (vlax-invoke sfso 'getfile file))
(setq f (vlax-get f 'attributes))
(vlax-release-object sfso)
f
)
)
)
(_fileatts "G:\\Ron\\test.dwg") @罗恩琼普
谢谢你这么做
你还知道如何设置ATT吗? 这似乎有效:
(defun _readonly (file flag / f n sfso)
(cond ((and (findfile file) (setq sfso (vlax-get-or-create-object "Scripting.FileSystemObject")))
(setq f (vlax-invoke sfso 'getfile file))
(setq n (vlax-get f 'attributes))
(cond (flag (and (/= 1 (rem n 32)) (vlax-put f 'attributes (1+ n))))
((and (= 1 (rem n 32)) (vlax-put f 'attributes (1- n))))
)
(vlax-release-object sfso)
)
)
)
;; Set read only
(_readonly "G:\\Ron\\test2.dwg" T)
;; Remove read only
(_readonly "G:\\Ron\\test2.dwg" nil) 好东西,罗恩! 很好,不过由于文件属性是位编码的,我建议用以下内容代替内部cond表达式:
(vlax-put f 'attributes (boole (if flag 7 4) 1 (vlax-get f 'attributes))) 谢谢
页:
[1]
2