Author Topic: File on desktop  (Read 6337 times)

0 Members and 1 Guest are viewing this topic.

rude dog

  • Guest
File on desktop
« on: October 26, 2004, 06:39:03 PM »
How do you create a textfile on the desktop via autolisp

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #1 on: October 26, 2004, 08:07:27 PM »
try this ....
Code: [Select]

(if (setq FN (open "full_path_to_text_file_on_desktop" "w"))
(close FN)
(alert "File not created")
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

rude dog

  • Guest
File on desktop
« Reply #2 on: October 26, 2004, 08:50:43 PM »
Code: [Select]
Command: (setq FN (open "C:\Documents and Setttings\All Users\Desktop\Tnew.txt" "w"))

#<file "C:Documents and SetttingsAll UsersDesktopTnew.txt">

Command: (WRITE-LINE "HERE IT IS" FN)

"HERE IT IS"

Command: (CLOSE FN)
nil

hmm.. still not creating a new text file to the desktop..what am I doing wrong

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
File on desktop
« Reply #3 on: October 26, 2004, 09:18:23 PM »
Try this:
Code: [Select]

(setq FN (open "C:\\Documents and Setttings\\All Users\\Desktop\\Tnew.txt" "w"))
TheSwamp.org  (serving the CAD community since 2003)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #4 on: October 26, 2004, 09:19:26 PM »
Your path is invalid. You need to correct the spelling of "Settings" and you need to either change your slashes to doubles "\\" or make them forward slashes "/"

As such:
Code: [Select]
(setq FN (open "C:\\Documents and Settings\\All Users\\Desktop\\Tnew.txt" "w"))
(WRITE-LINE "HERE IT IS" FN)
(CLOSE FN)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #5 on: October 26, 2004, 09:20:56 PM »
Dangit Mark, you beat me to it ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
File on desktop
« Reply #6 on: October 26, 2004, 09:22:11 PM »
Quote from: Keith
Dangit Mark, you beat me to it ...

Yea but I missed the spellling error.  :roll:
TheSwamp.org  (serving the CAD community since 2003)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #7 on: October 26, 2004, 09:27:27 PM »
Oh well we can't catch everything everytime....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

rude dog

  • Guest
File on desktop
« Reply #8 on: October 26, 2004, 09:37:45 PM »
Thank you  &  Thank you...Oh and Thank you :)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #9 on: October 26, 2004, 09:46:09 PM »
Uh ... you are welcome .... I think ... glad I could help
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
Re: File on desktop
« Reply #10 on: October 27, 2004, 05:31:37 AM »
Quote from: rude dog
How do you create a textfile on the desktop via autolisp

Alternatively .. or additionally:
Code: [Select]
(defun getDesktop (/ script spFolders desktop)
  (cond ((setq script (vlax-create-object "WScript.Shell"))
         (setq spFolders (vlax-get-property script "SpecialFolders")
               desktop   (vlax-invoke-method spFolders 'Item "Desktop")
         )
         (vlax-release-object spFolders)
         (vlax-release-object script)
        )
  )
  desktop
)

(defun makeDesktopFile (/ dsktopPath fn fName)
  (cond
    ((and (setq dsktopPath (getDesktop))
          (/= (setq fName (getstring "\nFilename: ")) "")
     )
     ;; assume a default of ".txt" if no extension was given
     (if (/= (substr fName (- (strlen fName) 3) 1) ".")
          (setq fName (strcat fName ".txt")))
     ;; go create file
     (cond ((setq fn
                   (open (setq fName (strcat dsktopPath "\\" fName)) "w"))
            (close fn)
            ;; and, if succesfull, open it in notepad
            (startapp "notepad.exe" fName)
           )
     )
    )
  )
  (princ)
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
File on desktop
« Reply #11 on: October 27, 2004, 07:48:11 AM »
Not as elegant as yours Stig but none the less....... :D
Code: [Select]

(defun make-file (/ getdesktop fn fp fo)

  ;; create a .txt file in 'C:\Documents and Settings\All Users\Desktop'
  ;; named by user, default extension is .txt

  (defun get-desktop (/ dir)
    (cond
      ((and
         (setq dir (strcat (getenv "ALLUSERSPROFILE") "\\Desktop\\"))
         (vl-file-directory-p dir))
       dir
       )
      )
    )

 (if (and
       (setq fn (getstring "\n(Default Ext = .txt) Filename: "))
       (/= fn ""); if the user hits <enter>
       )
   
   ; make user we *have* a desktop path
   (if (setq fp (get-desktop))

     (cond

       ; user supplied extension so we'll use it
       ((vl-filename-extension fn)
        (setq fo (open (strcat fp fn) "a"))
        )

       ; user did *not* supply extension so we'll
       ; add .txt to the file name
       ((not (vl-filename-extension fn))
        (setq fo (open (strcat fp fn ".txt") "a"))
        )
       )

     ; this probably isn't needed but what the heck!
     (alert "Path [ C:\Documents and Settings\All Users\Desktop ] not found")
     )
   )

 (if fo ; ok file name look good so we can proceed
   (progn
     (write-line "Hello from the Desktop" fo)
     (close fo)
     )
   )

 (princ)
 )
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
File on desktop
« Reply #12 on: October 27, 2004, 08:27:35 AM »
While we're on the subject of read/writ(e) ing to files, will someone explain how to properly use xmlin/xmlout? I know how to import the tlb. I just don't know what to do after that. Thank you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File on desktop
« Reply #13 on: October 27, 2004, 09:24:27 AM »
Oh the prevalence of code boggles the mind ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
File on desktop
« Reply #14 on: October 27, 2004, 10:02:41 AM »
(setq dir (strcat (getenv "ALLUSERSPROFILE") "\\Desktop\\"))

Mark, that's all fine but "Desktop" is in my localized version of Win2000 called "Skrivebord"  :)