9

windows 10, emacs 25.1, dired+

Suppose in folder I select 3 files. Something like this:

dired_select

Now I want 2 options:

  1. Copy to kill-ring the selected files names. So the result must be:

    ic_contact_us_write_us.png

    ic_in_store_green.png

    ic_m_brands_active.png

  2. Copy to kill-ring the full path of selected files names.

So the result must be:

d:/TEMP/1/drawable-hdpi/ic_contact_us_write_us.png

d:/TEMP/1/drawable-hdpi/ic_in_store_green.png

d:/TEMP/1/drawable-hdpi/ic_m_brands_active.png

Is it possible?

1 Answer 1

9

You can copy file names by pressing w. It calls the function dired-copy-filename-as-kill:

(dired-copy-filename-as-kill &optional ARG)

Copy names of marked (or next ARG) files into the kill ring. The names are separated by a space. With a zero prefix arg, use the absolute file name of each marked file.

Hence, in order to copy the full path of marked files to the kill ring, I've added the following piece of code:

(defun tl/dired-copy-path-at-point ()
    (interactive)
    (dired-copy-filename-as-kill 0))

(define-key dired-mode-map (kbd "W") 'tl/dired-copy-path-at-point)
4
  • Also a universal argument works: C-u 0 M-x w (I just learned) Oct 16, 2018 at 6:29
  • 3
    This answer should be updated. The interactive command dired-copy-filename-as-kill is correct, but the advice should really be to use the universal argument directly rather than defining another command. Simply use C-u 0 w (@RecencyEffect's comment probably contains a typo).
    – ebpa
    Mar 15, 2019 at 16:41
  • 1
    Why use C-u 0 w when C-0 w is simpler?
    – Andy
    Jul 23, 2020 at 21:25
  • This answer (killing a file) doesn't fully answer the question (killing the currently selected files which could be multiple files.)
    – rdrg109
    May 12, 2021 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.