Jump to content

Recommended Posts

Posted

Dear coders

 

 

I need a small routine to set a file's attribute (i.e. read-only or hidden )

As far as I know you need to use the Scripting.FileSystemObject but im not yet familiar with it

 

 

And the same routine should be able to read the same file and give me back the attributes that are set

The result of getting the att can also be in numbers

i.e. 2 is only hidden and 1 is only read only

2081 = Read-only + Archiving + contents indexed + compressed

 

 

Kind regards

Posted

What programing language are you trying to use?

Posted

Try acet-file-attr (ExpressTools).

Posted

Sorry for not being specific lol

 

*lisp is the language

Posted

Maybe this will get you started in the right direction:

(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")

Posted

@ronjonp

 

 

Thanks for this

Do you also know how to set the atts?

Posted

This seems to work:

(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)

Posted

Nice one Ron, though since the file attributes are bit-coded, I would suggest the following in place of your inner cond expression:

(vlax-put f 'attributes (boole (if flag 7 4) 1 (vlax-get f 'attributes)))

Posted

Thanks for the example Lee. I knew there was a better way to do it but took the sledgehammer approach as I wasn't seeing it. :)

Posted

Batch file example of cleaning up my autocad temporary drive

 

c:
cd\
cd acadtemp
del *.log
del *.ac$
del {*.*
del *.err
del {*.*
attrib etrans*.* -h
del etrans*.*

Posted

@everyone

 

Thanks for the code's this is what I need.

All are working fine

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...