00001 /** 00002 * @file file_manip.h 00003 * Useful file management helpers 00004 * 00005 * @remark Copyright 2002 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author Philippe Elie 00009 * @author John Levon 00010 */ 00011 00012 #ifndef FILE_MANIP_H 00013 #define FILE_MANIP_H 00014 00015 #include <string> 00016 #include <list> 00017 00018 00019 /** 00020 * copy_file - copy a file. 00021 * @param source filename to copy from 00022 * @param destination filename to copy into 00023 * 00024 * the last modification time of the source file is preserved, file attribute 00025 * and owner are preserved if possible. Return true if copying successful. 00026 */ 00027 bool copy_file(std::string const & source, std::string const & destination); 00028 00029 /// return true if dir is an existing directory 00030 bool is_directory(std::string const & dirname); 00031 00032 /** 00033 * is_file_identical - check for identical files 00034 * @param file1 first filename 00035 * @param file2 second filename 00036 * 00037 * return true if the two filenames belong to the same file 00038 */ 00039 bool is_files_identical(std::string const & file1, std::string const & file2); 00040 00041 /** 00042 * op_realpath - resolve symlinks etc. 00043 * Resolve a path as much as possible. Accounts for relative 00044 * paths (from cwd), ".." and ".". For success, the target 00045 * file must exist ! 00046 * 00047 * Resolve a symbolic link as far as possible. 00048 * Returns the original string on failure. 00049 */ 00050 std::string const op_realpath(std::string const & name); 00051 00052 /// return true if the given file is readable 00053 bool op_file_readable(std::string const & file); 00054 00055 /** 00056 * @param file_list where to store result 00057 * @param base_dir directory from where lookup start 00058 * @param filter a filename filter 00059 * @param recursive if true lookup in sub-directory 00060 * 00061 * create a filelist under base_dir, filtered by filter and optionally 00062 * looking in sub-directory. If we look in sub-directory only sub-directory 00063 * which match filter are traversed. 00064 */ 00065 bool create_file_list(std::list<std::string> & file_list, 00066 std::string const & base_dir, 00067 std::string const & filter = "*", 00068 bool recursive = false); 00069 00070 /** 00071 * op_dirname - get the path component of a filename 00072 * @param file_name filename 00073 * 00074 * Returns the path name of a filename with trailing '/' removed. 00075 */ 00076 std::string op_dirname(std::string const & file_name); 00077 00078 /** 00079 * op_basename - get the basename of a path 00080 * @param path_name path 00081 * 00082 * Returns the basename of a path with trailing '/' removed. 00083 * 00084 * Always use this instead of the C basename() - header order 00085 * can affect behaviour for basename("/") 00086 */ 00087 std::string op_basename(std::string const & path_name); 00088 00089 #endif /* !FILE_MANIP_H */
1.6.1