Elisp programming 4: File Operations

Source: Internet
Author: User
Tags symlink

Determine whether a file exists

 
(File-exists-P "~ /Test. El ")

See its help documentation:

 
File-exists-P is a built-in function in 'C source Code '. (file-exists-P filename) return T if file filename exists (whether or not you can read it .) see also 'file-readable-p' and 'file-bubutes '. this Returns nil for a symlink to a nonexistent file. use 'file-symlink-p' to test for such links.

If yes, t is returned.

Check whether a file exists and is readable

 
(File-readable-P "~ /Test. El ")

Check file attributes

 
(File-attributes "~ /Test. El "'string)

Or

(File-attributes "~ /Test. El "'integer)

The list in the above two rows displays the object attributes in the form of string or integer list, ranging from 0 to 11, with a total of 12 attributes.

You can obtain whether a file is a directory.

Example of a directory operation

Assume that the sub-directory names in a directory are all numbers, and find the directory name with the largest number.

 
(Setq file-name-List (directory-Files "/opt/share/upland_release" nil "[0-9] +" 'nosort )) (string-to-number (CAR file-name-list ))

For other file functions, see

The file-related chapter for the http://www.gnu.org/software/emacs/manual/html_mono/elisp.html.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.