Author Topic: folder network write permission...  (Read 3431 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
folder network write permission...
« on: April 26, 2006, 01:32:07 PM »
Hi all,..

I would like to know if it is possible in LISP to know if the current user have
some write permission in a specific folder..

for the moment i use this...

Code: [Select]
(setq filetemp (open (strcat setupfolder "\\" DEPARTEMENT "\\test.txt") "w"))
(close filetemp)
(if (findfile (strcat setupfolder "\\" SDC_DEPARTEMENT "\\test.txt"))
  (progn.....

but work only for who have write permission....

 :|
Keep smile...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: folder network write permission...
« Reply #1 on: April 26, 2006, 01:48:34 PM »
Try so:
Code: [Select]
(vl-file-copy
  (strcat setupfolder "\\" DEPARTEMENT "\\test.txt")
  (strcat (getenv "tmp") "\\test.txt")
) ;_  vl-file-copy

(setq filetemp (open (strcat (getenv "tmp") "\\test.txt") "w"))
(close filetemp)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: folder network write permission...
« Reply #2 on: April 26, 2006, 01:49:03 PM »
Quick and dirty --

Code: [Select]
(defun IsFolderWriteable ( foldername )
    (and
        (vl-file-directory-p foldername)
        (   (lambda ( tempfilename / handle )
                (if (setq handle (open tempfilename "w"))  
                    (progn
                        (close handle)
                        (vl-file-delete tempfilename)
                        t
                    )
                )
            )
            (vl-filename-mktemp "yaqada" foldername ".yep")
        )    
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: folder network write permission...
« Reply #3 on: April 26, 2006, 02:16:49 PM »
Try so:
Code: [Select]
(vl-file-copy
  (strcat setupfolder "\\" DEPARTEMENT "\\test.txt")
  (strcat (getenv "tmp") "\\test.txt")
) ;_  vl-file-copy

(setq filetemp (open (strcat (getenv "tmp") "\\test.txt") "w"))
(close filetemp)

thanks...ElpanovEvgeniy

But If I understand your code..
You copy the test.txt file from network to local...and than see if we can open from there !!?
hmm...not realy what i need...

But you give me some hint...

Code: [Select]
(setq filetemp (strcat setupfolder "\\" DEPARTEMENT "\\test.txt"))
(setq Fre (vl-file-copy currentexistingfile filetemp))
 
(if Fre
  (progn
  (vl-file-delete filetemp).....

Thanks...

I have lurn another think....again...;-)

« Last Edit: April 26, 2006, 02:40:24 PM by Andrea »
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: folder network write permission...
« Reply #4 on: April 26, 2006, 03:36:12 PM »
Another dick and quirty just for fun --

Code: [Select]
(defun IsFolderWriteable ( foldername )
    (and
        (vl-file-directory-p foldername)
        (   (lambda ( fso / result )
                (setq result
                    (zerop
                        (logand 1
                            (vlax-get
                                (vlax-invoke fso 'GetFolder foldername)
                                'Attributes
                            )
                        )
                    )
                )   
                (vlax-release-object fso)
                result
            )
            (vla-getinterfaceobject
                (vlax-get-acad-object)
                "Scripting.FileSystemObject"
            )
        )   
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: folder network write permission...
« Reply #5 on: April 26, 2006, 05:39:36 PM »
Edit: added missing local declaration.

I believe that first version may cause a memory leak because the implied folder object is not formally released. I'm leaving it intact for conversation sake.

Here's a variant that does formal cleanup --

Code: [Select]
(defun IsFolderWriteable ( foldername )
    (and
        (vl-file-directory-p foldername)
        (   (lambda ( / fso folder result )
                (setq result
                    (zerop
                        (logand 1
                            (vlax-get
                                (setq folder
                                    (vlax-invoke
                                        (setq fso
                                            (vla-getinterfaceobject
                                                (vlax-get-acad-object)
                                                "Scripting.FileSystemObject"
                                            )
                                        )   
                                       'GetFolder
                                        foldername
                                    )
                                )
                                'Attributes
                            )   
                        )
                    )
                )
                (vlax-release-object folder)
                (vlax-release-object fso)
                result
            )
        )
    )
)
« Last Edit: April 26, 2006, 05:46:40 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sdoman

  • Guest
Re: folder network write permission...
« Reply #6 on: April 28, 2006, 03:25:49 PM »
Code: [Select]
(defun IsFolderWriteable ( foldername )
    (and
        (vl-file-directory-p foldername)
        (   (lambda ( / fso folder result )
        ....

Nice function MP.  I am curious however, as to why you used Lambda in this situation?  Typically, I see it used as an argument to Mapcar or Apply.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: folder network write permission...
« Reply #7 on: April 28, 2006, 08:32:40 PM »
Nice function MP.  I am curious however, as to why you used Lambda in this situation?  Typically, I see it used as an argument to Mapcar or Apply.

1.One could use progn, but the parent code would have to declare the locals -- not necessarily a bad thing, but more and more I try to utilize discrete blocks of code / logic.
2.Down the road if one wished to extract that portion of the code to use as a separate function it's already formed (self contained) as such.
3.It's clean to me in an inexplicable way, but I fully admit -- I'm kinda funny that way.

:loco:

Thanks Steve.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sdoman

  • Guest
Re: folder network write permission...
« Reply #8 on: April 30, 2006, 12:37:25 AM »

1.One could use progn, but the parent code would have to declare the locals -- not necessarily a bad thing, but more and more I try to utilize discrete blocks of code / logic.
2.Down the road if one wished to extract that portion of the code to use as a separate function it's already formed (self contained) as such.
3.It's clean to me in an inexplicable way, but I fully admit -- I'm kinda funny that way.


I see the wisdom now.   Very creative usage.  Thanks for the lesson.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: folder network write permission...
« Reply #9 on: April 30, 2006, 10:59:31 AM »
Thank you Steve -- very generous comments.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst