fs.h.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <chapter xml:id="fs.h">
  2. <title><tt>__vic/fs.h</tt></title>
  3. <p>Filesystem utilities.</p>
  4. <note>All paths are expected to be UTF-8 encoded!</note>
  5. <chapter xml:id="path_exists">
  6. <title><tt>path_exists()</tt>, <tt>file_exists()</tt>, <tt>dir_exists()</tt>
  7. </title>
  8. <code-block lang="C++"><![CDATA[
  9. bool path_exists(const char *path);
  10. bool path_exists(const std::string &path);
  11. bool file_exists(const char *path);
  12. bool file_exists(const std::string &path);
  13. bool dir_exists(const char *path);
  14. bool dir_exists(const std::string &path);
  15. ]]></code-block>
  16. <p><tt>path_exists()</tt> checks whether the path exists in the system. Second
  17. and third functions additionally check, besides the presence, if the path
  18. references to a regular file or to a directory, respectively.</p>
  19. </chapter>
  20. <chapter xml:id="mkdir">
  21. <title><tt>mkdir()</tt>, <tt>mkdir_if_absent()</tt></title>
  22. <code-block lang="C++"><![CDATA[
  23. void mkdir(const char *path);
  24. void mkdir(const std::string &path);
  25. bool mkdir_if_absent(const char *path);
  26. bool mkdir_if_absent(const std::string &path);
  27. ]]></code-block>
  28. <p>Creates a directory. Throws exception in case of failure.
  29. <tt>mkdir_if_absent()</tt> returns <tt>false</tt> instead of throwing if
  30. the directory already exists.</p>
  31. </chapter>
  32. <chapter xml:id="rmdir">
  33. <title><tt>rmdir()</tt>, <tt>rmdir_if_exists()</tt></title>
  34. <code-block lang="C++"><![CDATA[
  35. void rmdir(const char *path);
  36. void rmdir(const std::string &path);
  37. bool rmdir_if_exists(const char *path);
  38. bool rmdir_if_exists(const std::string &path);
  39. ]]></code-block>
  40. <p>Deletes an empty directory. Throws exception in case of failure.
  41. <tt>rmdir_if_exists()</tt> returns <tt>false</tt> instead of throwing if
  42. the directory doesn't exist.</p>
  43. </chapter>
  44. <chapter xml:id="get_current_dir">
  45. <title><tt>get_current_dir()</tt></title>
  46. <code-block lang="C++"><![CDATA[
  47. std::string get_current_dir();
  48. ]]></code-block>
  49. <p>Returns current working directory.</p>
  50. </chapter>
  51. <chapter xml:id="remove_file">
  52. <title><tt>remove_file()</tt>, <tt>remove_file_if_exists()</tt>,
  53. <tt>remove_file_nt()</tt></title>
  54. <code-block lang="C++"><![CDATA[
  55. void remove_file(const char *path);
  56. void remove_file(const std::string &path);
  57. bool remove_file_if_exists(const char *path);
  58. bool remove_file_if_exists(const std::string &path);
  59. bool remove_file_nt(const char *path) noexcept;
  60. bool remove_file_nt(const std::string &path) noexcept;
  61. ]]></code-block>
  62. <p>Deletes the file. Throws exception in case of failure.</p>
  63. <p><tt>remove_file_if_exists()</tt> returns <tt>false</tt> instead of throwing
  64. if the file doesn't exist.</p>
  65. <p><tt>remove_file_nt()</tt> doestn't throw any exceptions at all,
  66. <tt>false</tt> is returned in case of failure.</p>
  67. </chapter>
  68. <chapter xml:id="copy_file">
  69. <title><tt>copy_file()</tt>, <tt>copy_file_if_exists()</tt>,
  70. <tt>copy_file_replace()</tt>, <tt>copy_file_replace_if_exists()</tt></title>
  71. <code-block lang="C++"><![CDATA[
  72. void copy_file(
  73. const char *src_path, const char *dest_path, bool replace = false);
  74. void copy_file(
  75. const std::string &src_path, const std::string &dest_path,
  76. bool replace = false);
  77. bool copy_file_if_exists(
  78. const char *src_path, const char *dest_path, bool replace = false);
  79. bool copy_file_if_exists(
  80. const std::string &src_path, const std::string &dest_path,
  81. bool replace = false);
  82. void copy_file_replace(
  83. const char *src_path, const char *dest_path);
  84. void copy_file_replace(
  85. const std::string &src_path, const std::string &dest_path);
  86. bool copy_file_replace_if_exists(
  87. const char *src_path, const char *dest_path);
  88. bool copy_file_replace_if_exists(
  89. const std::string &src_path, const std::string &dest_path);
  90. ]]></code-block>
  91. <p>Creates a new file <tt>dest_path</tt> which is a copy of a file
  92. <tt>src_path</tt>. If the new file exists and <tt>replace == false</tt>,
  93. the functions fail.</p>
  94. <p><tt>copy_file_if_exists()</tt> returns <tt>false</tt> instead of throwing
  95. if <tt>src_path</tt> doesn't exist.</p>
  96. <p><tt>copy_file_replace()</tt> is the same as <tt>copy_file(..., true)</tt>.
  97. </p>
  98. <p><tt>copy_file_replace_if_exists()</tt> is the same as
  99. <tt>copy_file_if_exists(..., true)</tt>.</p>
  100. </chapter>
  101. <chapter xml:id="move_file">
  102. <title><tt>move_file()</tt>, <tt>move_file_if_exists()</tt>,
  103. <tt>move_file_replace()</tt>, <tt>move_file_replace_if_exists()</tt></title>
  104. <code-block lang="C++"><![CDATA[
  105. void move_file(const char *src_path, const char *dest_path);
  106. void move_file(const std::string &src_path, const std::string &dest_path);
  107. bool move_file_if_exists(const char *src_path, const char *dest_path);
  108. bool move_file_if_exists(
  109. const std::string &src_path, const std::string &dest_path);
  110. void move_file_replace(const char *src_path, const char *dest_path);
  111. void move_file_replace(
  112. const std::string &src_path, const std::string &dest_path);
  113. bool move_file_replace_if_exists(
  114. const char *src_path, const char *dest_path);
  115. bool move_file_replace_if_exists(
  116. const std::string &src_path, const std::string &dest_path);
  117. ]]></code-block>
  118. <p>Moves a file <tt>src_path</tt> to new location specified by
  119. <tt>dest_path</tt>.</p>
  120. <p>The functions with <tt>_replace</tt> suffix overwrite existing destination
  121. file if exists, others - fail in such case.</p>
  122. <p><tt>move_file_if_exists()</tt> returns <tt>false</tt> instead of throwing
  123. if <tt>src_path</tt> doesn't exist.</p>
  124. </chapter>
  125. <chapter xml:id="rename_file">
  126. <title><tt>rename_file()</tt>, <tt>rename_file_if_exists()</tt>,
  127. <tt>rename_file_replace()</tt>, <tt>rename_file_replace_if_exists()</tt></title>
  128. <code-block lang="C++"><![CDATA[
  129. void rename_file(const char *src_name, const char *dest_name);
  130. void rename_file(const std::string &src_name, const std::string &dest_name);
  131. bool rename_file_if_exists(const char *src_name, const char *dest_name);
  132. bool rename_file_if_exists(
  133. const std::string &src_name, const std::string &dest_name);
  134. void rename_file_replace(const char *src_name, const char *dest_name);
  135. void rename_file_replace(
  136. const std::string &src_name, const std::string &dest_name);
  137. bool rename_file_replace_if_exists(
  138. const char *src_name, const char *dest_name);
  139. bool rename_file_replace_if_exists(
  140. const std::string &src_name, const std::string &dest_name);
  141. ]]></code-block>
  142. <p>Renames a file <tt>src_path</tt> to <tt>dest_path</tt>. The new path
  143. has to be located within the same physical filesystem.</p>
  144. <p>As opposed to <tt>std::rename()</tt>, the functions without
  145. <tt>_replace</tt> suffix fail if <tt>dest_path</tt> exists.</p>
  146. <p><tt>rename_file_if_exists()</tt> returns <tt>false</tt> instead of throwing
  147. if <tt>src_path</tt> doesn't exist.</p>
  148. </chapter>
  149. <chapter xml:id="file_size">
  150. <title><tt>file_size()</tt></title>
  151. <code-block lang="C++"><![CDATA[
  152. uintmax_t file_size(const char *path);
  153. uintmax_t file_size(const std::string &path);
  154. ]]></code-block>
  155. <p>Returns file size in bytes.</p>
  156. </chapter>
  157. </chapter>