cpp_filesystem - 8BitsCoding/RobotMentor GitHub Wiki
์ฌ์ฉ๋ฒ์ด๋ ํ์ํ๋ค๋ฉด ๊ฒ์ํด์ ์ฌ์ฉํ์!
- C++17์ ์๋ก์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- C++14๋ ๊ทธ ์ ์๋ ํ์ผ ์์คํ
๊ณผ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์ฑ์์์ ๋ํด ์ฐ์ฐ์ ํ ๋ฐฉ๋ฒ์ด ์์์
- ๊ฒฝ๋ก
- ์ผ๋ฐ ํ์ผ
- ๋๋ ํฐ๋ฆฌ
- ํ์ผ ์ฝ๊ธฐ์ ์ฐ๊ธฐ์ ๊ดํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๋
- ํ์ผ ์์ฑ ๋ณ๊ฒฝ, ๋๋ ํฐ๋ฆฌ ์ํ, ํ์ผ ๋ณต์ฌ ๋ฑ์ ๊ดํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- ์ด ๋ชจ๋ ๊ฑธ std::fs๋ก ํ ์ ์์.
- ํ๋ซํผ ๊ณตํต์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก ๊ฒฝ๋ก ํฉ์น๊ธฐ
- ํ์ผ๊ณผ ๋๋ ํฐ๋ฆฌ ๋ณต์ฌ, ์ด๋ฆ ๋ฐ๊พธ๊ธฐ, ์ญ์
- ๋๋ ํฐ๋ฆฌ์์ ํ์ผ, ๋๋ ํฐ๋ฆฌ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
- ํ์ผ ๊ถํ ์ฝ๊ธฐ ๋ฐ ์ค์
- ํ์ผ ์ํ ์ฝ๊ธฐ ๋ฐ ์ค์
#include <filesystem>
namespace fs = std::experimental::filesystem::v1;
// ์ปดํ์ผ๋ฌ์ ๋ฐ๋ผ std::filesystem์ผ ์ ์์.
int main() {
fs::path path1 = "D:\\Lecture";
fs::path path2 = "examples";
path /= path2;
// D:\\Lecture\\examples
fs::path path3 = "D:\\Lecture";
fs::path path4 = "exampels";
path3 += path4;
// D:\\Lectureexamples
fs::path path5 = "D:\\Lecture";
fs::path path6 = "\exampels";
path5 /= path6;
// D:\\exampels
return 0;
}
cppreference์์ ๋ค๋ฅธ ์์ ์ฐธ๊ณ
#include <filesystem>
namespace fs = std::experimental::filesystem::v1;
int main() {
fs::path originalTextPath = "C:\\exampels\\myRank.txt";
fs::path copiedTextPath = "C:\\exampels\\copiedMyRank.txt";
fs::path originalDirPath = "C:\\examples\\folder1";
fs::path copiedDirPath1 = "C:\\examples\\copiedfolder1";
fs::path copiedDirPath2 = "C:\\examples\\copiedfolder2";
fs::copy(originalTextPath, copiedTextPath);
// ํ์ผ ๋ณต์ฌ
fs::copy(originalDirPath, copiedDirPath1);
// ๋๋ ํฐ๋ฆฌ ๋ณต์ฌ (๋น์ฌ๊ท)
fs::copy(originalDirPath, copiedDirPath2, fs::copy_option::recursive);
// ๋๋ ํฐ๋ฆฌ ๋ณต์ฌ (์ฌ๊ท)
return 0;
}
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
int main() {
fs::path filePath = "C:\\exampels\\myRank.txt";
fs::path renamedPath = "C:\\exampels\\folder1\\rank.txt";
fs::rename(filePath, renamedPath);
return 0;
}
- ํ์ผ ๋๋ ๋๋ ํฐ๋ฆฌ์ ์ด๋ฆ์ ๋ฐ๊พธ๊ฑฐ๋ ์ด๋์ํจ๋ค.
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
int main() {
fs::path currentPath = fs::current_path();
fs::create_directories(currentPath / "data");
// ํ๋ก์ ํธ ํด๋์ ์ ํด๋๋ฅผ ๋ง๋ฆ
fs::remove(currentPath / "data");
return 0;
}
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
int main() {
for(auto& path : fs::recursive_directory_iterator("C:\\Lecture\\FilesysystemExample"))
{
std::cout << path << std::endl;
}
return 0;
}
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
void PrintPermission(fs::perms permission)
{
std::cout << ((permission & fs::perms::owner_read) != fs::perms::none ? "r" : "-")
// ...
// ๋ง์ผ๋ ๊ฒ์ํด ๋ณผ ๊ฒ
}
int main() {
fs::path filePath = "C:\\examples\\file.txt";
PrintPermission(fs::status(filePath).permissions());
}