```
(defun ledger-accounts-list-in-file (file)
"Return a list of all known account names from FILE as strings.
Considers both accounts listed in postings and those declared
with \"account\" directives."
(let ((accounts nil))
;; Check if file exists and is readable
(if (and (file-exists-p file) (file-readable-p file))
(with-temp-buffer
;; Insert file content into the buffer
(insert-file-contents file)
;; Process the buffer content
(setq accounts (ledger-accounts-in-buffer))
(when ledger-accounts-exclude-function
(setq accounts (cl-remove-if ledger-accounts-exclude-function accounts)))
(mapcar #'car accounts))
(error "File does not exist or is not readable: %s" file))))
```
#elisp #ledger-cli #emacs #ledger-mode