Next: , Previous: , Up: Files   [Contents][Index]


35.7 Changing File Names and Attributes

The functions in this section rename, copy, delete, link, and set the modes of files.

In the functions that have arguments newname and ok-if-already-exists, if a file by the name of newname already exists, the actions taken depend on the value of ok-if-already-exists:

Command: add-name-to-file filename newname &optional ok-if-already-exists

This function gives the file named filename the additional name newname. This means that newname becomes a new “hard link” to filename. Both these arguments must be strings.

In the first part of the following example, we list two files, foo and foo3.

% ls -l fo*
-rw-rw-rw-  1 rms       29 Aug 18 20:32 foo
-rw-rw-rw-  1 rms       24 Aug 18 20:31 foo3

Then we evaluate the form (add-name-to-file "~/lewis/foo" "~/lewis/foo2"). Again we list the files. This shows two names, foo and foo2.

(add-name-to-file "~/lewis/foo1" "~/lewis/foo2")
     ⇒ nil
% ls -l fo*
-rw-rw-rw-  2 rms       29 Aug 18 20:32 foo
-rw-rw-rw-  2 rms       29 Aug 18 20:32 foo2
-rw-rw-rw-  1 rms       24 Aug 18 20:31 foo3

Finally, we evaluate the following:

(add-name-to-file "~/lewis/foo" "~/lewis/foo3" t)

and list the files again. Now there are three names for one file: foo, foo2, and foo3. The old contents of foo3 are lost.

(add-name-to-file "~/lewis/foo1" "~/lewis/foo3")
     ⇒ nil
% ls -l fo*
-rw-rw-rw-  3 rms       29 Aug 18 20:32 foo
-rw-rw-rw-  3 rms       29 Aug 18 20:32 foo2
-rw-rw-rw-  3 rms       29 Aug 18 20:32 foo3

This function is meaningless on non-Unix systems, where multiple names for one file are not allowed.

See also file-nlinks in File Attributes.

Command: rename-file filename newname &optional ok-if-already-exists

This command renames the file filename as newname.

If filename has additional names aside from filename, it continues to have those names. In fact, adding the name newname with add-name-to-file and then deleting filename has the same effect as renaming, aside from momentary intermediate states.

In an interactive call, this function prompts for filename and newname in the minibuffer; also, it requests confirmation if newname already exists.

Command: copy-file filename newname &optional ok-if-already-exists time

This command copies the file filename to newname. An error is signaled if filename does not exist.

If time is non-nil, then this functions gives the new file the same last-modified time that the old one has. (This works on only some operating systems.)

In an interactive call, this function prompts for filename and newname in the minibuffer; also, it requests confirmation if newname already exists.

Command: delete-file filename

This command deletes the file filename, like the shell command ‘rm filename’. If the file has multiple names, it continues to exist under the other names.

A suitable kind of file-error error is signaled if the file does not exist, or is not deletable. On Unix, a file is deletable if its directory is writable.

See also delete-directory in Create/Delete Dirs.

Command: make-symbolic-link filename newname &optional ok-if-already-exists

This command makes a symbolic link to filename, named newname. This is like the shell command ‘ln -s filename newname’.

In an interactive call, this function prompts for filename and newname in the minibuffer; also, it requests confirmation if newname already exists.

Function: set-file-modes filename mode

This function sets mode bits of filename to mode (which must be an integer). Only the low 12 bits of mode are used.

Function: set-default-file-modes mode

This function sets the default file protection for new files created by SXEmacs and its subprocesses. Every file created with SXEmacs initially has this protection. On Unix, the default protection is the bitwise complement of the “umask” value.

The argument mode must be an integer. Only the low 9 bits of mode are used.

Saving a modified version of an existing file does not count as creating the file; it does not change the file’s mode, and does not use the default file protection.

Function: default-file-modes

This function returns the current default protection value.


Next: , Previous: , Up: Files   [Contents][Index]