Function: url-dav-directory-files

url-dav-directory-files is a byte-compiled function defined in url-dav.el.gz.

Signature

(url-dav-directory-files URL &optional FULL MATCH NOSORT FILES-ONLY)

Documentation

Return a list of names of files in URL.

There are three optional arguments: If FULL is non-nil, return absolute URLs. Otherwise return names
 that are relative to the specified URL.
If MATCH is non-nil, mention only file names that match the regexp MATCH. If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
 NOSORT is useful if you plan to sort the result yourself.

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-dav.el.gz
(defun url-dav-directory-files (url &optional full match nosort files-only)
  "Return a list of names of files in URL.
There are three optional arguments:
If FULL is non-nil, return absolute URLs.  Otherwise return names
 that are relative to the specified URL.
If MATCH is non-nil, mention only file names that match the regexp MATCH.
If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
 NOSORT is useful if you plan to sort the result yourself."
  (let ((properties (url-dav-get-properties url '(DAV:resourcetype) 1))
	(child-url nil)
	(child-props nil)
	(files nil)
	(parsed-url (url-generic-parse-url url)))

    (when (and (= (length properties) 1)
	       (not (url-dav-file-directory-p url)))
      (signal 'file-error (list "Opening directory" "Not a directory" url)))

    (while properties
      (setq child-props (pop properties)
	    child-url (pop child-props))
      (if (and (eq (plist-get child-props 'DAV:resourcetype) 'DAV:collection)
	       files-only)
	  ;; It is a directory, and we were told to return just files.
	  nil

	;; Fully expand the URL and then rip off the beginning if we
	;; are not supposed to return fully-qualified names.
	(setq child-url (url-expand-file-name child-url parsed-url))
	(if (not full)
	    ;; Parts of the URL might be hex'ed.
	    (setq child-url (substring (url-unhex-string child-url)
				       (length url))))

	;; We don't want '/' as the last character in filenames...
	(if (string-match "/$" child-url)
	    (setq child-url (substring child-url 0 -1)))

	;; If we have a match criteria, then apply it.
	(if (or (and match (not (string-match match child-url)))
		(string= child-url "")
		(string= child-url url))
	    nil
	  (push child-url files))))

    (if nosort
	files
      (sort files 'string-lessp))))