help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newlines in file names


From: Whitfield Diffie
Subject: Newlines in file names
Date: Mon, 10 Dec 2012 11:47:54 -0800

Question: How do you translate a filename containing a newline to one containing
          a \n without getting a \\n.

Problem: Create a directory ``test''.

         In the directory create a file with (call-process "touch" nil
nil nil "Icon\n").
         This file's name has five characters of which the last is a
newline. (Such files
         appear in some downloads.)

         This directory now appears as

                /Users/diffie/test:
                total used in directory 0 available 327738716
                drwxr-xr-x   3 diffie  staff  102 Dec 10 11:04 .
                drwxr-xr-x  25 diffie  staff  850 Dec 10 11:03 ..
                -rw-r--r--   1 diffie  staff    0 Dec  9 10:01 Icon

         Place the cursor on the line with the Icon file and type

                <esc>: (file-exists-p (dired get filename))

         The response is ``nil''.

         Make the buffer writable with <ctrl-x><ctrl-q> and edit the
         name by hand to ``Icon\n''.  Type

                <esc>: (file-exists-p (dired-get-filename))

         The response is now ``t''.

         Type g to revert the buffer and the name returns to being ``Icon''.

         Place the cursor on the line with the Icon file again and type

                M+x

         The entire file line disappears leaving only . and ..  in the
directory.

         Type g to revert the buffer and the line reappears but the file
         has not become executable.

         Edit the filename as before and repeat the attempt to make it
executable.

         Now the file line becomes

                -rwxr-xr-x   1 diffie  staff    0 Dec  9 10:01 Icon

         The file has become executable but its name has returned to being
         ``Icon'', lacks the newline character.

Objective: Repair dired so that filenames containing newlines are displayed
           with \n in place of newline characters (and \r in place of carriage
           returns).

           I have tried setting print-escape-newlines to t and recoding
           filename with buffer-file-coding-system, file-name-coding-system,
           and default-file-name-coding-system, without success.


                                             Whit



reply via email to

[Prev in Thread] Current Thread [Next in Thread]