(defun copy-filename-as-kill ()
"Copy BUFFER's full pathname into the kill ring.
If prefix arg is 0, copy the directory part.
If prefix arg is other than nil and 0, copy the basename."
(interactive)
(let ((s
(if (= 0 (prefix-numeric-value current-prefix-arg))
default-directory
(if (buffer-file-name)
(if (null current-prefix-arg)
(buffer-file-name)
(file-name-nondirectory (buffer-file-name)))
""))))
(kill-new s)))