Find File
Function Syntax | (LM:findfile <fnm> <dir>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
fnm | String | File to search (inc. extension), e.g. "MyFile.txt" |
dir | String | Root directory to search from |
Returns | ||
Type | Description | |
String | Full filename of file if found, else nil |
Function Description
This function will recursively search all directories beneath (and including) a root directory for a specified file.
If found, the full filename will be returned; otherwise, this subfunction will return nil.
Select all
;; Findfile - Lee Mac ;; Searches the supplied directory and all subdirectories of the supplied directory for the specified file. ;; fnm - [str] File to search, e.g. "MyFile.txt" ;; dir - [str] Root directory ;; Returns: [str] Full filename of file if found, else nil. (defun LM:findfile ( fnm dir ) (setq dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir))) (cond ( (findfile (strcat dir "\\" fnm))) ( (vl-some '(lambda ( x ) (LM:findfile fnm (strcat dir "\\" x))) (vl-remove "." (vl-remove ".." (vl-directory-files dir nil -1))) ) ) ) )
Example Function Call
_$ (LM:findfile "MyFile.txt" "C:\\MyFolder") "C:\\MyFolder\\SubFolder\\MyFile.txt"