(defun org-agenda-files (&optional unrestricted archives)
"Get the list of agenda files.
Optional UNRESTRICTED means return the full list even if a restriction
is currently in place.
When ARCHIVES is t, include all archive files that are really being
used by the agenda files. If ARCHIVE is `ifmode', do this only if
`org-agenda-archives-mode' is t."
(let ((files
(cond
((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
((stringp org-agenda-files) (org-read-agenda-file-list))
((listp org-agenda-files) org-agenda-files)
(t (error "Invalid value of `org-agenda-files'")))))
(setq files (apply 'append
(mapcar (lambda (f)
(if (file-directory-p f)
(directory-files
f t org-agenda-file-regexp)
(list (expand-file-name f org-directory))))
files)))
(when org-agenda-skip-unavailable-files
(setq files (delq nil
(mapcar (lambda (file)
(and (file-readable-p file) file))
files))))
(when (or (eq archives t)
(and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
(setq files (org-add-archive-files files)))
files))