Jump to content

(findfile) not working as expected


guitarguy1685

Recommended Posts

So I have this weird situation.  In a list I have the following line

(findfile "C:\\Windows\\Fonts\\arial.ttf")

It returns "nil" on my home computer but it returns the path on my work computer.  It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. 

 

I thought it could be permission thing because looking for files in the root directory, but I can find other files in the Windows folder.  I don't know what I'm doing wrong. 

 

This  happens on ACAD 2020 and ACAD2021

Edited by guitarguy1685
Link to comment
Share on other sites

9 hours ago, guitarguy1685 said:

So I have this weird situation.  In a list I have the following line


(findfile "C:\\Windows\\Fonts\\arial.ttf")

It returns "nil" on my home computer but it returns the path on my work computer.  It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. 

 

I thought it could be permission thing because looking for files in the root directory, but I can find other files in the Windows folder.  I don't know what I'm doing wrong. 

 

This  happens on ACAD 2020 and ACAD2021

 

 

hi, 

not sure this alternative working? 

;
;(defun _findfile (fn)
;  (if ((lambda (l) (vl-directory-files (car l)
;	     (apply 'strcat (cdr l))
;	    )
;       )
;	 (fnsplitl fn)
;      )
;    fn
;  )
;)

;;if findfile null , attempt to search local directory 
;;"c:\\windows\\" ---> "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\" 

(defun _findfile (fn)
  (cond
    ;; search as "C:\\windows\\Fonts\\arial.ttf"
    ((findfile fn))
    ;; search local as "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\fonts\\arial.ttf"
    ((findfile
       (strcat (getenv "userprofile")
	       "\\AppData\\Local\\Microsoft\\Windows\\"
	       (vl-string-left-trim "c:\\windows" (strcase fn t))
       )
     )
    )
    ;; search in ACAD directory only as "arial.ttf"
    ((findfile (vl-string-left-trim
		 (vl-filename-directory
		   fn
		 )
		 fn
	    )
     )
    )
  )
)

try

( _findfile "C:\\Windows\\Fonts\\arial.ttf" )

 

Edited by hanhphuc
findfile local sorted by OP
Link to comment
Share on other sites

3 hours ago, guitarguy1685 said:

It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. 

Did you check that the 'arial.ttf' file is in that location?

Link to comment
Share on other sites

28 minutes ago, ronjonp said:

Did you check that the 'arial.ttf' file is in that location?

Okay so it appears to be a windows thing. When I go to C:\Windows\Fonts, Windows10  uses some "font display window", different from file explorer.  On both computers the font shows that Arial is installed. 

 

However if I use UNC convention to view the folder such as "\\computer-name\C$\Windows\Fonts" i can view the folder in a standard file explorer view.  When I do this, I only see the arial.ttf on my work station and not my home desktop.  So while Arial is installed on my home desktop the file is somewhere else. I'll find it. 

 

So the (findfile) is working as it should. 

Link to comment
Share on other sites

I found it.  This font is installed on my user folder.  %userprofile%\AppData\Local\Microsoft\Windows\Fonts

 

I didn't know that was a thing. 

Link to comment
Share on other sites

1 hour ago, guitarguy1685 said:

I found it.  This font is installed on my user folder.  %userprofile%\AppData\Local\Microsoft\Windows\Fonts

 

I didn't know that was a thing. 

Glad you got it sorted! 👍

Link to comment
Share on other sites

8 hours ago, hanhphuc said:

I completely glossed over the fact that your solution includes searches in user profile and root directory. That would've solved my issue.

 

hi, 

not sure this alternative working? 


;
;(defun _findfile (fn)
;  (if ((lambda (l) (vl-directory-files (car l)
;	     (apply 'strcat (cdr l))
;	    )
;       )
;	 (fnsplitl fn)
;      )
;    fn
;  )
;)

;;if findfile null , attempt to search local directory 
;;"c:\\windows\\" ---> "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\" 

(defun _findfile (fn)
  (cond
    ;; search as "C:\\windows\\Fonts\\arial.ttf"
    ((findfile fn))
    ;; search local as "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\fonts\\arial.ttf"
    ((findfile
       (strcat (getenv "userprofile")
	       "\\AppData\\Local\\Microsoft\\Windows\\"
	       (vl-string-left-trim "c:\\windows" (strcase fn t))
       )
     )
    )
    ;; search in ACAD directory only as "arial.ttf"
    ((findfile (vl-string-left-trim
		 (vl-filename-directory
		   fn
		 )
		 fn
	    )
     )
    )
  )
)

try


( _findfile "C:\\Windows\\Fonts\\arial.ttf" )

 

 

Link to comment
Share on other sites

The following should present a far more reliable method across multiple systems:

(defun LM:findfontfile ( fnt / dir )
    (if (setq dir (LM:specialfolder "fonts"))
        (progn
            (eval
                (list 'defun 'LM:findfontfile '( fnt )
                    (list 'findfile
                        (list 'strcat
                            (vl-string-right-trim "\\"
                                (vl-string-translate "/" "\\" dir)
                            )
                            "\\" 'fnt
                        )
                    )
                )
            )
            (LM:findfontfile fnt)
        )
    )
)

;; Special Folder  -  Lee Mac
;; Queries the WshSpecialFolders collection for the specified folder
;; Ref: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx

(defun LM:specialfolder ( fld / rtn spf wsh )
    (if (setq wsh (vlax-get-or-create-object "wscript.shell"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                   '(lambda ( )
                        (setq spf (vlax-get-property wsh 'specialfolders))
                        (vlax-invoke-method spf 'item fld)
                    )
                )
            )
            (if spf (vlax-release-object spf))
            (vlax-release-object wsh)
            (if (not (vl-catch-all-error-p rtn)) rtn)
        )
    )
)

(vl-load-com) (princ)
_$ (LM:findfontfile "arial.ttf")
"C:\\Windows\\Fonts\\arial.ttf"

 

  • Like 3
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...