Jump to content

How to check if a specific Letter Drive exists


guitarguy1685

Recommended Posts

I would like to check if a Drive exists on a computer.

 

I'm writing a lisp that will setup all support paths automatically. The user will be prompted as to whether they want the support paths pointing to their Local "C" drive or pointing to the server.

 

if they want it to point to their local, I want to run a check to see if the following path exists

 

"C:\CompanyCAD".

 

If they want to point to the server I need to check if they have this drive mapped out

 

"L:\Engineering\CompanyCAD

 

I can still set the paths without them having access to either drive, I just want to send a warning if they don't.

 

If your wondering why some people need local access. Some work offsite and load our CAD library on their local and work that way because running AutoCAD with VPN kind of sucks. Not sure if that's ACAD's problem or their ISP.

Link to comment
Share on other sites

The following function will return a list of the drive letters in use:

;; Drive Letters  -  Lee Mac
;; Returns a list of drive letters currently in use

(defun LM:driveletters ( / fso rtn )
   (if (setq fso (vlax-create-object "scripting.filesystemobject"))
       (progn
           (vl-catch-all-apply
              '(lambda ( )
                   (vlax-for obj (vlax-get fso 'drives)
                       (setq rtn (cons (vlax-get obj 'driveletter) rtn))
                   )
               )
           )
           (vlax-release-object fso)
           (vl-sort rtn '<)
       )
   )
)

 

Also posted here:

https://www.theswamp.org/index.php?topic=47396.msg524127#msg524127

Link to comment
Share on other sites

Alternative, assuming A:

; List all available disks (A: to Z:).
(defun KGA_File_DiskList ()
 (vl-remove-if-not
   'vl-file-directory-p
   '("A:" "B:" "C:" "D:" "E:" "F:" "G:" "H:" "I:" "J:" "K:" "L:" "M:" "N:" "O:" "P:" "Q:" "R:" "S:" "T:" "U:" "V:" "W:" "X:" "Y:" "Z:")
 )
)

Link to comment
Share on other sites

@Roy,

I'd use:

_$ (mapcar (function (lambda (x) (strcat x ":"))) (mapcar 'chr (vl-string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
("A:" "B:" "C:" "D:" "E:" "F:" "G:" "H:" "I:" "J:" "K:" "L:" "M:" "N:" "O:" "P:" "Q:" "R:" "S:" "T:" "U:" "V:" "W:" "X:" "Y:" "Z:")

This is not a big deal, just for the lazy code writers.

Link to comment
Share on other sites

Another. :)

 

(defun Drives ( / i d l )
;; Tharwat - Date: 24.Apr.2017 ;;
 (setq i 64)
 (while (< i 91)
   (if (vl-file-directory-p (setq d (strcat (chr (setq i (1+ i))) ":")))
     (setq l (cons d l)))
   )
 (vl-sort l '<))

Link to comment
Share on other sites

Here's another, using Windows Management Instrumentation:

(defun LM:wmidriveletters ( / qry rtn srv wmi )
   (if (setq wmi (vlax-create-object "wbemscripting.swbemlocator"))
       (progn
           (vl-catch-all-apply
              '(lambda ( )
                   (vlax-for itm
                       (setq srv (vlax-invoke wmi 'connectserver)
                             qry (vlax-invoke srv 'execquery "SELECT DeviceID FROM Win32_LogicalDisk")
                       )
                       (vlax-for prp (vlax-get itm 'properties_)
                           (if (= "DeviceID" (vlax-get prp 'name))
                               (setq rtn (cons (vlax-get prp 'value) rtn))
                           )
                       )
                   )
               )
           )
           (foreach obj (list qry srv wmi)
               (if (= 'vla-object (type obj))
                   (vlax-release-object obj)
               )
           )
           (vl-sort rtn '<)
       )
   )
)

Link to comment
Share on other sites

The following function will return a list of the drive letters in use:
;; Drive Letters  -  Lee Mac
;; Returns a list of drive letters currently in use

(defun LM:driveletters ( / fso rtn )
   (if (setq fso ([b][color="red"]vlax-create-object "scripting.filesystemobject"[/color][/b]))
       (progn
           (vl-catch-all-apply
              '(lambda ( )
                   (vlax-for obj (vlax-get fso 'drives)
                       (setq rtn (cons (vlax-get obj 'driveletter) rtn))
                   )
               )
           )
           (vlax-release-object fso)
           (vl-sort rtn '<)
       )
   )
)

 

Also posted here:

https://www.theswamp.org/index.php?topic=47396.msg524127#msg524127

 

okay, wtf!? :lol: How does one even know that stuff is available? I did a google search on "scripting.filesystemobject" and this is what I found

 

FileSystemObject

 

Is this a list of properties i can access via "vlax-create-object"?

Link to comment
Share on other sites

This may be usefull, note the first part which checks for directories ie drives.

 

; resets the paths usefull for update versions of Autocad
; by A H 2011
; This sets a reference to the install path of your product
; the gets are their for info maybe other use
; use this to find other settings 
;(vlax-dump-object (vla-get-files (vla-get-preferences (vlax-get-Acad-object))) T)



(vl-load-com)
(defun setpaths ( / *files* doc) 
; make temp directory
(if (vl-file-directory-p "C:\\Acadtemp\\")
(Princ "Acadtemp exists")
(vl-mkdir "C:\\AcadTEMP\\")
)


(setq *files*  (vla-get-files  (vla-get-preferences (vlax-get-Acad-object))))

; savepath
;(vla-get-AutoSavepath *files*)
(vla-put-AutoSavepath *files* "C:\\AcadTemp")

; custom icons
;(vla-get-CustomIconPath *files*))
(vla-put-CustomIconPath *files* "P:\\Autodesk\\ICONS")

; custom menu
;(vla-get-Menufile *files*))
;(vla-put-Menufile  *files* "C:\\Users\\2013COGG")

; printers config
;(vla-get-PrinterConfigPath *files*)
(vla-put-PrinterConfigPath *files* "P:\\AutoDESK\\Plotting\\Plot Styles 2011")

; printers style sheet
;(vla-get-PrinterStyleSheetPath *files*)
(vla-put-PrinterStyleSheetPath *files* "P:\\AutoDESK\\Plotting\\Plot Styles")

; printer drv's
;(vla-get-PrinterDescPath *files*)
(vla-put-PrinterDescPath *files* "P:\\AutoDESK\\Plotting\\Drv")

; print spooler
;(vla-get-PrintSpoolerPath *files*)
(vla-put-PrintSpoolerPath *files* "C:\\AcadTemp\\")

; template  path
;(vla-get-TemplateDwgPath *files*)
(vla-put-TemplateDwgPath *files* "P:\\Autodesk\\c3d Templates")

; template location
;(vla-get-QnewTemplateFile *files*)
(vla-put-QnewTemplateFile *files* "P:\\Autodesk\\c3d Templates\\gg.dwt")

;make new support paths exist + new
(setq paths (vla-get-SupportPath *files*))
(setq coggpaths "P:\\autodesk\\supportfiles;P:\\autodesk\\lisp;P:\\autodesk\\fonts;")
(setq newpath (strcat coggpaths paths))
(vla-put-SupportPath *files* newpath)

; Tempdirectory 
;(vla-get-TempFilePath *files*))
(vla-put-TempFilePath *files* "C:\\AcadTemp\\")

;   PlotLogFilePath = "C:\\Documents and Settings\\ah\\localsettings\\application data\\autodesk\\c3d 2011\\enu\\"
(vla-put-PlotLogFilePath *files* "C:\\AcadTemp\\")

;   LogFilePath = "C:\\Documents and Settings\\ah\\localsettings\\application data\\autodesk\\c3d 2011\\enu\\"
(vla-put-LogFilePath *files* "C:\\AcadTemp\\")


; xref temp path
;(vla-get-TempXrefPath *files*))
(vla-put-TempXrefPath *files* "C:\\AcadTemp\\")

; end use of *files*
)
(setpaths)

; exit quitely
(princ "All Done")

Link to comment
Share on other sites

Makes me wonder, how do you know so much about COM ? Is this is your main resource? :geek:

 

Yes - the full WMI reference may be found here.

 

okay, wtf!? :lol: How does one even know that stuff is available? I did a google search on "scripting.filesystemobject" and this is what I found

 

FileSystemObject

 

Is this a list of properties i can access via "vlax-create-object"?

 

The link to which you refer is a list of the properties available for an instance of the FileSystemObject (FSO). The vlax-create-object function allows you to instantiate a class, allowing you to access the properties & methods of the class.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...