Author Topic: How do I find the location of MyDocuments folder?  (Read 11880 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #30 on: April 26, 2011, 05:34:02 PM »
This is where I was going with it:

(setq olduserfolder1 (vl-filename-directory (findfile "acad.pgp")))
(substr olduserfolder1 1 (vl-string-position (ascii "\\") olduserfolder1 0 t))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #31 on: April 26, 2011, 06:16:59 PM »
Ted you can also use something like this if you know how many folders to chop off the end. Gives you a bit more flexibility.

Code: [Select]
(defun _chop (string delimeter #2chop / n)
  (setq n -1)
  (while
    (and (setq p (vl-string-position (ascii delimeter) string 0 t)) (< (setq n (1+ n)) #2chop))
     (setq string (substr string 1 p))
  )
  string
)

;;Little test

  (setq n 0)
  (repeat 10 (alert (_chop (vl-filename-directory (findfile "acad.pgp")) "\\" (setq n (1+ n)))))


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I find the location of MyDocuments folder?
« Reply #32 on: April 26, 2011, 07:56:54 PM »
Thanks guys. That gives me something to chew on tomorrow while I am work.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How do I find the location of MyDocuments folder?
« Reply #33 on: April 26, 2011, 08:03:30 PM »
Another for fun:

Code: [Select]
(defun _chop ( dir n / p )
  (if (and (setq p (vl-string-position 92 (vl-string-right-trim "\\" dir) 0 t)) (< 0 n))
    (_chop (substr dir 1 p) (1- n))
    dir
  )
)

Code: [Select]
(setq n 0) (repeat 10 (print (_chop (findfile "acad.pgp") (setq n (1+ n)))))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I find the location of MyDocuments folder?
« Reply #34 on: May 08, 2011, 07:53:53 AM »
(findfile ".") is interesting.

This goes back to the days of DOS. Every directory (folder) contains two "files" - A single dot represents the "current" directory (folder); two dots represents the parent of the current directory (folder), i.e., the part of the path returned by single dot with the current directory chopped off. And while that is initally the "Start in" folder listed in the ACAD shortcut, some commands, such as SAVEAS, can change the current directory to whatever directory is selected for the "Save to". This can be very bothersome when some user settings are predicated on the current directory always being the Start in folder.

Late to the party but thought all may find this interesting.
From an old thread, not mine.
Quote
I noticed a long time a go to, that findfile behaves quite rare... here are
some of the non-document stuff I found and maybe others here already know.

(findfile "c:\\blocks\\122d\\12EBED01.DWG") ;;ok

(findfile "c:\\blocks\\122d\\") ;;wrong

(findfile "c:\\blocks\\122d\\.") ;;ok

;; find path...
(findfile "c:\\blocks\\ada\\...")
"C:\\blocks\\ada\\"

(findfile "c:\\blocks\\ada\\..")
"C:\\blocks"

;; get current directory...
(findfile "cd\\..")
"C:\\Program Files\\AutoCAD 2000i"

;; get main directory...
(findfile "c:..")
"C:\\Program Files"

;; get the root...
(findfile "\\.")
(findfile "/..")
(findfile "\\..")
"C:\\"

(findfile "\\program files\\autocad 2000i.")
"C:\\program files\\autocad 2000i"

;; get current directory...
(findfile "cd\\..")
"C:\\Program Files\\AutoCAD 2000i"

;; get main directory...
(findfile "c:..")
"C:\\Program Files"

;; get the root...
(findfile "\\.")
"C:\\"


;; for a particular folder
(if (setq path (findfile "acetutil.fas"))
  (vl-filename-directory path))

"C:\\Program Files\\AutoCAD 2000i\\express"
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How do I find the location of MyDocuments folder?
« Reply #35 on: May 08, 2011, 07:59:07 AM »
Interesting CAB - thanks  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #36 on: May 09, 2011, 09:32:27 AM »
Very interesting. Thanks for sharing, Alan.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I find the location of MyDocuments folder?
« Reply #37 on: May 09, 2011, 09:41:00 AM »
Very interesting. Thanks for sharing, Alan.
Like he said.  Thanks CAB
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I find the location of MyDocuments folder?
« Reply #38 on: May 09, 2011, 09:55:34 AM »
Quite welcome. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.