Author Topic: Get Folder  (Read 2540 times)

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Get Folder
« on: October 03, 2007, 11:50:56 AM »
Is there a way to get a folder path without selecting a file in the folder?

Sorta like getfiled but selecting a folder not a file.  :mrgreen:


T.Willey

  • Needs a day job
  • Posts: 5213
Re: Get Folder
« Reply #1 on: October 03, 2007, 11:56:52 AM »
Many variations of this have been posted, and this is Tony T.'s changed by me.
Code: [Select]
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey
;; 16 Will let you type in the path
;; 64 Will let you create a new folder

  (vl-load-com)
  (setq sh
     (vla-getInterfaceObject
        (vlax-get-acad-object)
        "Shell.Application"
     )
  )


  (setq folder
     (vlax-invoke-method
         sh
         'BrowseForFolder
         (vla-get-HWND (vlax-get-Acad-Object))
         Message
         0 ; This is the bit number to change.
      )
  )
  (vlax-release-object sh)


  (if folder
     (progn
        (setq folderobject
           (vlax-get-property folder 'Self)
        )
        (setq result
           (vlax-get-property FolderObject 'Path)
        )
        (vlax-release-object folder)
        (vlax-release-object FolderObject)
        (if (/= (substr result (strlen result)) "\\")
          (setq result (strcat result "\\"))
          result
        )
     )
  )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Guest

  • Guest
Re: Get Folder
« Reply #2 on: October 03, 2007, 11:58:47 AM »
I've used this for a while now (got it from the now defunct AcadX.com site)

Code: [Select]
;;;==================================================================
;;; (JustPath cFileName)
;;; Returns the path portion of a complete path and file name.
;;;------------------------------------------------------------------
;;; Parameters:
;;; cFileName str to check
;;;------------------------------------------------------------------
;;; Returns:
;;; [STR]
;;; Example: (setq a "C:\\MyFolder\\MyFile.txt")
;;; (JustPath a) ; returns "C:\MyFolder"
;;;------------------------------------------------------------------
(defun JustPath (cFileName / bsLoc)
   (setq bsLoc (rat "\\" cfileName))
   (if   (> bsLoc 0)
      (substr cFilename 1 (1- bsLoc))
      ""
   ) ;_ end of if
) ;_ end of defun

deegeecees

  • Guest
Re: Get Folder
« Reply #3 on: October 03, 2007, 12:04:34 PM »
Thanks Tim, I had needed this in the past, but never had time/success in creating/finding something similar. Looks like I'll be digging into some old projects. Fun, fun, fun...

 :lol:

T.Willey

  • Needs a day job
  • Posts: 5213
Re: Get Folder
« Reply #4 on: October 03, 2007, 12:22:01 PM »
Thanks Tim, I had needed this in the past, but never had time/success in creating/finding something similar. Looks like I'll be digging into some old projects. Fun, fun, fun...

 :lol:
Digging in old routines is MAJOR FUN!  :wink:  Glad I don't have to do it.  You're welcome ...... I guess.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10333
Re: Get Folder
« Reply #5 on: October 03, 2007, 12:44:30 PM »
Matt,
Code: [Select]
(vl-filename-directory "c:\\MyFolder\\MyFile.txt")
"C:\\MyFolder
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.

T.Willey

  • Needs a day job
  • Posts: 5213
Re: Get Folder
« Reply #6 on: October 03, 2007, 12:48:02 PM »
Matt,

  You would also need to share the function 'Rat'.
Quote
Command: (JustPath Path)
; error: no function definition: RAT
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Guest

  • Guest
Re: Get Folder
« Reply #7 on: October 03, 2007, 01:00:57 PM »
Matt,
Code: [Select]
(vl-filename-directory "c:\\MyFolder\\MyFile.txt")
"C:\\MyFolder

Puh-tay-toe, Puh-tah-toe   :wink:

Thanks, CAB.

Guest

  • Guest
Re: Get Folder
« Reply #8 on: October 03, 2007, 01:02:00 PM »
Matt,

  You would also need to share the function 'Rat'.
Quote
Command: (JustPath Path)
; error: no function definition: RAT

D'oh!

Code: [Select]
;;;===========================================================================
;;; (Rat cSearchExpression cExpressionSearched)
;;; Returns the numeric position of the last (rightmost)
;;; occurrence of a character string within another character string.
;;;---------------------------------------------------------------------------
;;; Parameters:
;;; cSearchExpression [STR] - String to search for
;;; cExpressionSearched [STR] - String to search
;;;---------------------------------------------------------------------------
;;; Returns:
;;; [INT] - Posistion of the string
;;; Example: (setq a "A Lot of Text.")
;;; (Rat "Text" a) ; returns 10
;;;===========================================================================
(defun Rat (cSearch cSearchIn / return SearchFor cont n)
;; We need to escape for special characters
(cond
(
(= cSearch "\\")
(setq SearchFor "*`\\*")
)
(
(= cSearch ".")
(setq SearchFor "*`.*")
)
(
(= cSearch "#")
(setq SearchFor "*`#*")
)
(
(= cSearch "*")
(setq SearchFor "*`**")
)
(
(= cSearch "~")
(setq SearchFor "*`~*")
)
(
(= cSearch "-")
(setq SearchFor "*`-*")
)
(
(= cSearch ",")
(setq SearchFor "*`,*")
)
(
(= cSearch "`")
(setq SearchFor "*``*")
)
(
T
(setq SearchFor (strcat "*" cSearch "*"))
)
) ;_ end of cond

(cond
(
;; Make sure there is a match
(not (wcmatch cSearchIn SearchFor))
(setq return 0)
)
(
T
(setq n (strlen cSearchIn))
(setq TestStr (substr cSearchIn n))
(setq cont T)
(while Cont
(if (wcmatch TestStr SearchFor)
(progn
(setq Cont nil)
(setq return n)
) ;_ end of progn
(progn
(setq n (1- n))
(setq TestStr (substr cSearchIn n))

) ;_ end of progn
) ;_ end of if
) ;_ end of while
)
) ;_ end of cond
return
) ;_ end of defun

FengK

  • Guest
Re: Get Folder
« Reply #9 on: October 03, 2007, 01:04:38 PM »
fyi, if you're using doslib or don't mind using it, since version 7.0, it has a new function that displays an AutoCAD-style file selection dialog box. the syntax is:
(dos_getfilenav title default ext flags) when flags is set to 2048, it allows you to pick a folder.

ASMI

  • Guest
Re: Get Folder
« Reply #10 on: October 03, 2007, 01:19:01 PM »
Or OpenDCL BrowseFolder function

Quote
--------------------------------------------------------------------------------

Method BrowseFolder as String
 
This method will prompt the user with a dialog box that allows the selection of directory folders only. 


AutoLISP Syntax:
(Setq rValue (dcl_BrowseFolder 
          Caption [as String]
          [Optiona]/DefaultDirectory [as String]
          [Optional]/RootFolder [as String]
          [Optional]/Flags [as String]))


<Flags> is a bit flag, and its default value is 1 (to return only file system folders). The following values used for <Flags> are from the Windows SDK header file in hexadecimal:
 
BIF_RETURNONLYFSDIRS 0x0001
BIF_DONTGOBELOWDOMAIN 0x0002
BIF_STATUSTEXT 0x0004
BIF_RETURNFSANCESTORS 0x0008
BIF_EDITBOX 0x0010
BIF_VALIDATE 0x0020
BIF_NEWDIALOGSTYLE 0x0040
BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
BIF_BROWSEINCLUDEURLS 0x0080
BIF_UAHINT 0x0100
BIF_NONEWFOLDERBUTTON 0x0200
BIF_NOTRANSLATETARGETS 0x0400
BIF_BROWSEFORCOMPUTER 0x1000
BIF_BROWSEFORPRINTER 0x2000
BIF_BROWSEINCLUDEFILES 0x4000
BIF_SHAREABLE 0x8000 (remote shares, requires BIF_USENEWUI)
 
See MSDN for information about each flag.
With the new combination of arguments, the flag argument will not be necessary for duplicating the original behavior and more, but it might still be fun to check out the new style UI (flag value decimal 81).

Edit: METHOD!
« Last Edit: October 03, 2007, 01:23:34 PM by ASMI »