Author Topic: Searching for Paths  (Read 2645 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Searching for Paths
« on: July 13, 2014, 06:18:26 AM »
Hello guys  :-)

Is there  any way to get paths of these in any computer ?

1- My Documments
2- MyComputer Icon
3- Local Drives
4- Desktop

thanks in advance .

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Searching for Paths
« Reply #1 on: July 13, 2014, 08:55:23 AM »
Try the following function:

Code - Auto/Visual Lisp: [Select]
  1. ;; Special Folder  -  Lee Mac
  2. ;; Queries the WshSpecialFolders collection for the specified folder
  3. ;; Ref: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx
  4.  
  5. (defun LM:SpecialFolder ( folder / res spf wsh )
  6.     (setq res
  7.         (vl-catch-all-apply
  8.             (function
  9.                 (lambda ( )
  10.                     (setq wsh (vlax-get-or-create-object "wscript.shell")
  11.                           spf (vlax-get-property wsh 'specialfolders)
  12.                     )
  13.                     (vlax-invoke-method spf 'item folder)
  14.                 )
  15.             )
  16.         )
  17.     )
  18.     (if spf  (vlax-release-object  spf))
  19.     (if wsh  (vlax-release-object  wsh))
  20.     (if (not (vl-catch-all-error-p res))
  21.         res
  22.     )
  23. )

Reference: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx

Example:
Code - Auto/Visual Lisp: [Select]
  1. (LM:SpecialFolder "Desktop")
Code - Auto/Visual Lisp: [Select]
  1. (LM:SpecialFolder "MyDocuments")

Coder

  • Swamp Rat
  • Posts: 827
Re: Searching for Paths
« Reply #2 on: July 13, 2014, 08:56:16 AM »
I think this is work for desktop  :-)

(strcat (getenv "userprofile") "\\Desktop")

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Searching for Paths
« Reply #3 on: July 13, 2014, 08:59:40 AM »
There are also:
Code: [Select]
(getenv "UserName")
(getenv "UserProfile")
(getenv "ComputerName")
(getenv "Windir")
(getenv "SystemDrive")
(getenv "SystemRoot")

Coder

  • Swamp Rat
  • Posts: 827
Re: Searching for Paths
« Reply #4 on: July 13, 2014, 09:09:48 AM »
Thank you Lee for your help  :-)

I am sure your codes in first reply is very advanced that works instead of getenv functions . correct ?

I am trying to get all names of drives besides the system drive (getenv "SystemDrive")  but I failed .

Many many thanks for your help Lee

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Searching for Paths
« Reply #5 on: July 13, 2014, 09:18:45 AM »
I am trying to get all names of drives besides the system drive (getenv "SystemDrive")  but I failed .

Code - Auto/Visual Lisp: [Select]
  1. ;; Drive Letters  -  Lee Mac
  2. ;; Returns a list of drive letters currently in use
  3.  
  4. (defun LM:driveletters ( / fso rtn )
  5.     (if (setq fso (vlax-create-object "scripting.filesystemobject"))
  6.         (progn
  7.             (vl-catch-all-apply
  8.                '(lambda ( )
  9.                     (vlax-for obj (vlax-get fso 'drives)
  10.                         (setq rtn (cons (vlax-get obj 'driveletter) rtn))
  11.                     )
  12.                 )
  13.             )
  14.             (vlax-release-object fso)
  15.             (vl-sort rtn '<)
  16.         )
  17.     )
  18. )
Code - Auto/Visual Lisp: [Select]
  1. (LM:driveletters)

hanhphuc

  • Newt
  • Posts: 64
Re: Searching for Paths
« Reply #6 on: July 13, 2014, 09:26:41 AM »
more folders http://ss64.com/vb/special.html
the icon should get registry

@Thanx sir Lee  :-) nice utility
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

Coder

  • Swamp Rat
  • Posts: 827
Re: Searching for Paths
« Reply #7 on: July 13, 2014, 09:30:01 AM »
Perfect  :-)

Thank you so much Lee .

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Searching for Paths
« Reply #8 on: July 13, 2014, 09:52:52 AM »
You're welcome guys  :-)

Coder

  • Swamp Rat
  • Posts: 827
Re: Searching for Paths
« Reply #9 on: July 13, 2014, 10:24:45 AM »
more folders http://ss64.com/vb/special.html
the icon should get registry

@Thanx sir Lee  :-) nice utility

Thank you hanhphuc for your reply .

I don't know about VB but I think your link is the same codes that Lee posted in his first reply . right ?

Many thanks .  :-)