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

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
How do I find the location of MyDocuments folder?
« on: April 19, 2011, 03:22:38 PM »
Using lisp, what do I use to find the location of MyDocuments folder?

FindFile will not work here  because the users MyDocuments folders resides between the parallel universe of the server and client machine.  I am being a wise flower and it long story as to why I want Autocad to find and it and not me hard coding the path into my code.  One reason is that I want to see if really knows where the folder is and not it following my path blindly.

The path as seen in the options dialog is
Code: [Select]
\\cws-server\users\ted krush\my documents\
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

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #1 on: April 19, 2011, 03:25:57 PM »
Code: [Select]
(getvar 'MYDOCUMENTSPREFIX)
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 #2 on: April 19, 2011, 03:33:03 PM »
Duhh!  "prefix"  I never thought of searching by prefix!   Thanks.
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

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #3 on: April 19, 2011, 03:33:58 PM »
Duhh!  "prefix"  I never thought of searching by prefix!   Thanks.
I opened SYSVDLG and typed in *doc*. :-D
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #4 on: April 19, 2011, 03:52:08 PM »
Doesn't answer you question but here's a peek to the "special" folders:

Code: [Select]
(defun c:test (/ n out sa sp)
  (and (setq sa (vlax-create-object "WScript.Shell"))
       (setq sp (vlax-get sa 'specialfolders))
       (setq n -1)
       (repeat (vlax-get sp 'length) (setq out (cons (vla-item sp (setq n (1+ n))) out)))
       (alert (vl-prin1-to-string out))
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #5 on: April 19, 2011, 03:58:41 PM »
Very nice, Ron.

also...
Code: [Select]
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #6 on: April 19, 2011, 04:34:50 PM »
Very nice, Ron.

also...
Code: [Select]
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"

:)  What is (findfile ".") pointing to?
Mine prints "C:\\Program Files\\Aqua Engineering, Inc\\WatermarkID 2009"

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #7 on: April 19, 2011, 04:36:43 PM »
Very nice, Ron.

also...
Code: [Select]
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"

:)  What is (findfile ".") pointing to?
Mine prints "C:\\Program Files\\Aqua Engineering, Inc\\WatermarkID 2009"
Sorry, I meant type out the question of what it returns for you.  :ugly:
I stumbled across that the other day and was quite puzzled by it - works with ".." also.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: How do I find the location of MyDocuments folder?
« Reply #8 on: April 19, 2011, 04:42:32 PM »
I believe this returns the "Start in" folder specified in the shortcut used to start acad.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #9 on: April 19, 2011, 04:47:02 PM »
I believe this returns the "Start in" folder specified in the shortcut used to start acad.
I'm using pinned shortcuts in Win7, so that's probably why I'm receiving my documents folder. Interesting.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #10 on: April 19, 2011, 04:52:43 PM »
I believe this returns the "Start in" folder specified in the shortcut used to start acad.

Looks to be the case here. Thanks Jeff.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

laidbacklarry

  • Guest
Re: How do I find the location of MyDocuments folder?
« Reply #11 on: April 19, 2011, 06:04:42 PM »
(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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #12 on: April 19, 2011, 06:44:59 PM »
(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.
Very interesting. I never considered the days of running DOS and typing cd.. to back up one directory folder.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How do I find the location of MyDocuments folder?
« Reply #13 on: April 19, 2011, 07:27:21 PM »
I'd probably go with the SpecialFolders object, but for more cat-skinning:

Code: [Select]
(vl-registry-read "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" "Personal")

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: How do I find the location of MyDocuments folder?
« Reply #14 on: April 19, 2011, 07:52:36 PM »
What do you mean `dos days' (I sense some nostalgia). ...I still use those dots.

My entry.
(getstring "\nEnter the path to your \"My Documents\" folder: ")


:p
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #15 on: April 19, 2011, 10:05:32 PM »
I'd probably go with the SpecialFolders object
Why, is the system variable too simple?
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 #16 on: April 20, 2011, 06:17:42 AM »
 :-D  Wow! you guys ran with this one.  :-D

I'd probably go with the SpecialFolders object
Why, is the system variable too simple?
Not for me it isn't.  It curls up very nicely inside my simple mind.
The more complex methods is for more complex minds.
 :-D :-D

Thanks again guys.

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

laidbacklarry

  • Guest
Re: How do I find the location of MyDocuments folder?
« Reply #17 on: April 20, 2011, 08:14:53 AM »
Nostalgia? maybe.

On the other hand... there are some things you can do faster and easier in DOS. Our application includes a simple command - DOS - which opens a DOS window. If I can get a user to DOS, I can tell him/her Type this, Type that... and before you know it, we've done what needs to be done. I tell a user to open "Windows Explorer" and they almost always start "Internet Explorer"...

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: How do I find the location of MyDocuments folder?
« Reply #18 on: April 20, 2011, 08:46:21 AM »
I am a comand prompt junkie (well that comes froms being a *nix user though too).

AutoCAD conversations:
"type in: sh <enter> <enter> ..."
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I find the location of MyDocuments folder?
« Reply #19 on: April 20, 2011, 08:58:41 AM »
Okay next question.  
LOCALROOTPREFIX gives me this = "C:\\Users\\Ted Krush\\AppData\\Local\\Autodesk\\ACA 2010\\enu\\"

Is there something out there that will get me this = "C:\\Users\\Ted Krush\\AppData\\Local  <=== back  slashes can be present or not.
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 #20 on: April 20, 2011, 09:03:20 AM »
getenv TMP or TEMP may get you close  :wink:

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #21 on: April 20, 2011, 09:14:33 AM »
What Lee said:


(substr (getenv "Temp") 1 (vl-string-search "\\Temp" (getenv "Temp")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #22 on: April 20, 2011, 09:18:00 AM »
getenv TMP or TEMP may get you close  :wink:
FYI: That will abbreviate the folder names if they are too long.

eg.
Code: [Select]
Command: (getenv "Tmp")
"C:\\Users\\ATHOMP~1\\AppData\\Local\\Temp"
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 #23 on: April 20, 2011, 11:20:18 AM »
What Lee said:


(substr (getenv "Temp") 1 (vl-string-search " \\Temp"(getenv "Temp")))

Okay how did you do that?  and by that I mean tell to "delete" the " \\Temp" from the string?

The vl-string-search function searches the string not deletes from my reading the help file on vl-string-search. 

<sigh> I wish the help was little more dynamic when it comes to holding my hand.
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

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How do I find the location of MyDocuments folder?
« Reply #24 on: April 20, 2011, 11:22:36 AM »
What Lee said:


(substr (getenv "Temp") 1 (vl-string-search " \\Temp"(getenv "Temp")))

Okay how did you do that?  and by that I mean tell to "delete" the " \\Temp" from the string?

The vl-string-search function searches the string not deletes from my reading the help file on vl-string-search. 

<sigh> I wish the help was little more dynamic when it comes to holding my hand.
Look at the substr in the beginning of the call.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #25 on: April 20, 2011, 11:26:39 AM »
Look at the SUBSTR function (which does the trimming)

(vl-string-search " \\Temp"(getenv "Temp")) returns a number where the string "\\Temp" starts.

SUBSTR starts at a point in a string (in this case the beginning (1)) then stops at the beginning of "\\Temp" which was returned by the vl-string-search.

Maybe this will help you see it:


Code: [Select]
(setq string (getenv "Temp"))
;;If "\\Temp" is found in string
(if (setq p (vl-string-search "\\Temp" string))
  ;;Trim the string
  (substr string 1 p)
  ;;Else return the full string
  string
)


« Last Edit: April 20, 2011, 11:31:32 AM by ronjonp »

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 #26 on: April 20, 2011, 11:37:01 AM »
Ahh the search is returning numerical position of where \\Temp starts in the string.

Me gets it now.  Thanks again.
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

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #27 on: April 20, 2011, 11:53:43 AM »
Ahh the search is returning numerical position of where \\Temp starts in the string.

Me gets it now.  Thanks again.


:) Glad to help out.

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 #28 on: April 26, 2011, 04:02:06 PM »
How do I trim the right side of a sting to certain known character with unknown characters in between.

Quote
"\\\\server\\users\\ted krush\\my documents\\Folder name varies\\ To be trimmed but folder name also varies \\"

I can not get either vl-string-right-trim or Substr functions to fit.

I am trying to slice it and dice it using this ginzo code and it not working.
Code: [Select]
  (setq OldUserFolder1 (vl-filename-directory (findfile "acad.pgp")))
  (setq OldUserFolder2 (vl-string-right-trim "\\" OldUserFolder1))

A little push please?
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

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How do I find the location of MyDocuments folder?
« Reply #29 on: April 26, 2011, 04:50:22 PM »
If I understand the question look into this:
(vl-string-position char-codestr [start-pos [from-end-p]])
Arguments

char-code
The integer representation of the character to be searched.

str
The string to be searched.

start-pos
The position to begin searching from in the string (first character is 0); 0 if omitted.

from-end-p
If T is specified for this argument, the search begins at the end of the string and continues backward to pos


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 #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.