mv
Abstract
Function to move file and directory
Header file
namespace sstd{
bool mv (const char* pPath_src, const char* pPath_dst);
bool mv (const std::string& path_src, const char* pPath_dst);
bool mv (const char* pPath_src, const std::string& path_dst);
bool mv (const std::string& path_src, const std::string& path_dst);
}
Description
Function name | Description |
---|---|
mv() | A function to move file and directory from src-path to dst-path. ファイルやディレクトリを src-path から dst-path へ移動させる関数. |
Usage
move file to file
- main.cpp
#include <sstd/sstd.hpp> int main(){ sstd::mkdir("./tmp/01"); sstd::mkdir("./tmp/02"); sstd::system("touch ./tmp/01/example.txt"); sstd::mv("./tmp/01/example.txt", "./tmp/02/example.txt"); printf("./tmp/01: \n "); fflush(stdout); sstd::system("ls ./tmp/01"); printf("\n"); printf("./tmp/02: \n "); fflush(stdout); sstd::system("ls ./tmp/02"); sstd::rm("./tmp"); }
- Execution result
./tmp/01: ./tmp/02: example.txt
move file to directory
- main.cpp
#include <sstd/sstd.hpp> int main(){ sstd::mkdir("./tmp/01"); sstd::mkdir("./tmp/02"); sstd::system("touch ./tmp/01/example.txt"); sstd::mv("./tmp/01/example.txt", "./tmp/02"); printf("./tmp/01: \n "); fflush(stdout); sstd::system("ls ./tmp/01"); printf("\n"); printf("./tmp/02: \n "); fflush(stdout); sstd::system("ls ./tmp/02"); sstd::rm("./tmp"); }
- Execution result
./tmp/01: ./tmp/02: example.txt
move directory to directory
- main.cpp
#include <sstd/sstd.hpp> int main(){ sstd::mkdir("./tmp/01"); sstd::mkdir("./tmp/02"); sstd::system("touch ./tmp/01/example.txt"); sstd::mv("./tmp/01", "./tmp/02"); printf("./tmp/01: \n "); fflush(stdout); sstd::system("ls ./tmp/01"); printf("\n"); printf("./tmp/02: \n "); fflush(stdout); sstd::system("ls ./tmp/02"); sstd::rm("./tmp"); }
- Execution result
./tmp/01: ls: ./tmp/01: No such file or directory ./tmp/02: 01
Implementation
- Source: sstd/src/file/mv.cpp
- Header: sstd/src/file/mv.hpp
- Test: test/src_test/file/mv.cpp