kalai Posted May 11, 2012 Posted May 11, 2012 Hi , I know filename ( file.dvb) i want to know the filepath in autolisp. findfile searches in searchpath only. But file may be anywhere else. Can anyone help me? Quote
MSasu Posted May 11, 2012 Posted May 11, 2012 Please check if the functions provided here are helping you. Quote
kalai Posted May 11, 2012 Author Posted May 11, 2012 Hi, Let me explain, I have my dvb file , may be placed anywhere(not static) I want to load the file filepath is not known, only filename(file.dvb) is known. Quote
MSasu Posted May 11, 2012 Posted May 11, 2012 OK, I was under impression that you want to see the path from were was loaded an already loaded DVB. You can write a recursive routine to search all folders from all available drives, but this will not be a very effective approach. To narrow the search I suggest you to use a dedicated folder placed in the root of a drive (local or network). (foreach theDrive '("C:\\" "D:\\" "E:\\") (if (setq isValidPath (findfile (strcat theDrive "MyDVBFolder\\" "File.DVB"))) (setq pathDVB isValidPath) ) ) May use the McNeel's DosLib function DOS_DRIVEP to validate availability of a drive. Quote
MSasu Posted May 11, 2012 Posted May 11, 2012 This will search on all possible drives and retain the first valid path encountered: (setq listDrives '() index 66) (foreach theDrive (reverse (repeat 24 (setq listDrives (cons (chr (setq index (1+ index))) listDrives)))) (if (setq isValidPath (findfile (strcat theDrive ":\\MyDVBFolder\\" "File.DVB"))) (if (not pathDVB) (setq pathDVB isValidPath)) ) ) Quote
ketxu Posted May 12, 2012 Posted May 12, 2012 @MSASU : you can use WMI to get list of all Drives ^^ Quote
MSasu Posted May 13, 2012 Posted May 13, 2012 Thanks for your suggestion, ketxu! I will have to investigate that. Quote
pBe Posted May 13, 2012 Posted May 13, 2012 FSO for drive letters (defun _ValidDriveLetters (/ fso dr) (setq fso (vlax-create-object "Scripting.FileSystemObject")) (vlax-for d (vlax-get fso 'Drives) (setq dr (cons (vla-get-path d) dr))) (vlax-release-object fso) (reverse dr) ) (_ValidDriveLetters) ("C:" "D:" "E:" "V:") Quote
Lee Mac Posted May 13, 2012 Posted May 13, 2012 @pBe, why path over driveletter property? FSO: (defun _driveletters ( / fso reslt ) (if (setq fso (vlax-create-object "scripting.filesystemobject")) (progn (vl-catch-all-apply '(lambda ( ) (vlax-for drive (vlax-get fso 'drives) (setq reslt (cons (vlax-get drive 'driveletter) reslt)) ) ) ) (vlax-release-object fso) (vl-sort reslt '<) ) ) ) WMI: (defun _wmidriveletters ( / qry rslt srv wmi ) (vl-catch-all-apply '(lambda ( ) (setq wmi (vlax-create-object "wbemscripting.swbemlocator") srv (vlax-invoke wmi 'connectserver) qry (vlax-invoke srv 'execquery "Select DeviceID from Win32_LogicalDisk") ) (vlax-for itm qry (vlax-for prop (vlax-get itm 'properties_) (if (eq "DeviceID" (vlax-get prop 'name)) (setq rslt (cons (vlax-get prop 'value) rslt)) ) ) ) ) ) (foreach obj (list qry srv wmi) (if obj (vlax-release-object obj))) (vl-sort rslt '<) ) Quote
pBe Posted May 13, 2012 Posted May 13, 2012 @pBe, why path over driveletter property? To include ":" Another for Mapped Newtwork Drive letter and name (defun _NetDrive (/ WscrptO Driveletter NDrive) (setq WscrptO (vlax-create-object "WScript.Network") Driveletter (vlax-invoke WscrptO 'EnumNetworkDrives) ) (repeat (setq i (vla-get-length Driveletter)) (setq NDrive (cons (vla-Item Driveletter (setq i (1- i))) NDrive)) ) (vlax-release-object WscrptO) NDrive) Quote
Recommended Posts
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.