DGRL 发表于 2022-7-5 15:30:00

获取并设置文件属性ch

亲爱的程序员
 
 
我需要一个小例程来设置文件的属性(即只读或隐藏)
据我所知,您需要使用脚本。FileSystemObject,但我还不熟悉
 
 
同一个例程应该能够读取同一个文件,并返回设置的属性
获取att的结果也可以是数字
i、 e.2仅隐藏,1仅为只读
2081=只读+存档+内容索引+压缩
 
 
亲切的问候

SLW210 发表于 2022-7-5 15:38:53

你想用什么编程语言?

Roy_043 发表于 2022-7-5 15:42:02

请尝试acet file attr(ExpressTools)。

DGRL 发表于 2022-7-5 15:45:19

很抱歉没有具体说明lol
 
*lisp是一种语言

ronjonp 发表于 2022-7-5 15:54:51

也许这会让你朝着正确的方向开始:
(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")

DGRL 发表于 2022-7-5 15:59:03

@罗恩琼普
 
 
谢谢你这么做
你还知道如何设置ATT吗?

ronjonp 发表于 2022-7-5 16:01:13

这似乎有效:
(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)

Grrr 发表于 2022-7-5 16:08:06

好东西,罗恩!

Lee Mac 发表于 2022-7-5 16:10:35

很好,不过由于文件属性是位编码的,我建议用以下内容代替内部cond表达式:
(vlax-put f 'attributes (boole (if flag 7 4) 1 (vlax-get f 'attributes)))

ronjonp 发表于 2022-7-5 16:17:16

谢谢
页: [1] 2
查看完整版本: 获取并设置文件属性ch