vl-file-delete删除只读文件代码的使用方法
就是先把文件改为只读取,这个代码国外论坛找的,但是怎么用?没看明白....例如我想把文件只读属性去掉。(defun SetRO (/ afile fso ofile ro)(cond
((and (setq aFile (getfiled "" "" "" 4))
(setq fso (vlax-create-object "Scripting.FilesystemObject"))
(setq oFile (vlax-invoke fso 'GetFile aFile))
)
(vlax-put-property oFile 'Attributes (setq ro (- 1 (logand 1 (vlax-get-property oFile 'Attributes)))))
(princ (strcat "File set to " (nth ro '("Read-write" "Read-only"))))
(vlax-release-object oFile)
(vlax-release-object fso)
)
)
(princ)
)
本帖最后由 nyistjz 于 2021-8-17 12:38 编辑
[*](defun av:att-RO-f ()
[*](and
[*] (findfile file)
[*] (setq fso (vlax-create-object "Scripting.FilesystemObject"))
[*] (setq oFile (vlax-invoke fso 'GetFile File));易报错(发生意外),原因尚不清楚
[*])
[*])
[*];查询文件的读写属性,0为可读写,1为只读,返回参数为ATT。
[*](defun av:get-att-RO (file / att);需要引用属性参数时,ATT参数外置即可
[*](av:att-RO-f)
[*](setq att (logand 1 (vlax-get-property oFile 'Attributes)))
[*])
[*];文件属性读写修改,value=0为可写,1为只读,2为改变读写属性
[*](defun av:put-att-RO (file value)
[*](cond
[*] ((av:att-RO-f)
[*] (if (= value 2)(setq value (- 1 (logand 1 (vlax-get-property oFile 'Attributes)))))
[*] (vlax-put-property oFile 'Attributes value)
[*] (princ (strcat "\n文件" file "属性已设为:" (nth value '("可读写!" "只读!"))))
[*] (vlax-release-object oFile)
[*] (vlax-release-object fso)
[*] )
[*])
[*])
如果只想改为可读写
(av:put-att-RO file 0)
页:
[1]