In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article to share with you is about linux to determine whether the existence of the directory method, Xiaobian feel quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.
File systems are involved in work, and sometimes it is necessary to determine whether files and directories exist. I combine APUE chapter 4 files and directories, summarize how to correctly determine whether files and directories exist, convenient for later query.
stat series function
The stat function returns structural information about a file. The stat family of functions has three cases, corresponding to file names, file descriptors, and symbolic link files. stat structure describes the attributes of a file, mainly including file type, file size, and so on. The detailed stat structure is as follows:
struct stat { mode_t st_mode; // file type & mode(permissions) ino_t st_ino; // i-node number(serial number) dev_t st_dev; // device number(filesystem) dev_t st_rdev; // device number for specials files nlink_t st_nlink; // number of links uid_t st_uid; // user ID of owner gid_t st_gid; // group ID of owner off_t st_size; // size in bytes, for regular files time_t st_atime; // time of last access time_t st_mtime; // time of last modification time_t st_ctime; // time of last file status change long st_blksize; // best I/O block size long st_blocks; // number of 512-byte blocks allocated};
We can use stat to get information such as file type and file size. File types are: ordinary file, directory file, block special file, character special file, FIFO, socket and symbolic link. To determine whether a file or directory exists through stat series functions, when the stat function is executed, if the file exists, it is further determined whether the file is a normal file or a directory file.
stat series function error returns-1, error code is stored in errno, errno values are as follows:
1. The file specified by ENOENT parameter file_name does not exist.2. The directory in ENOTDIR path exists but is not a real directory.3. The file to be opened by ELOOP has too many symbolic links, the upper limit is 16 symbolic links. 4. The EFAULT parameter buf is an invalid pointer, pointing to a memory space that cannot exist. 5. The file access is rejected. 6. ENOMEM core memory is insufficient. 7. ENAMETOOLONG parameter file_name path name is too long above is linux to determine whether the directory exists, Xiaobian believes that some knowledge points may be our daily work will see or use. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.