This C++ File and Directory Management Library provides a comprehensive API for performing various file and directory operations. It is designed to simplify tasks like file creation, deletion, reading, and directory management with an intuitive interface.
-
File Operations
- Path Management: Get file paths and directories.
- File Management: Create, delete, copy, rename, and check file existence.
- Content Operations: Read from or write to files.
- Metadata Retrieval:
- File size
- Number of lines
- Last modification time
-
Directory Operations
- Path Management: Get directory paths and normalize paths.
- Directory Management: Create, delete, rename, clear contents, and check existence.
- Content Operations:
- Retrieve all files in a directory.
- Count files in a directory.
- Get total file sizes and line counts.
-
Utilities
- Normalize paths and handle absolute/relative paths.
- Cross-platform support for path separators.
-
Prerequisites
- C++ 11 or later
-
Clone the Repository
git clone https://github.com/jiafie7/file-system.git
cd file-system
- Build the Project
mkdir build
cd build
cmake ..
make
- Example code
#include "fs/file.h"
#include "fs/directory.h"
using namespace melon::fs;
int main()
{
File f1("./../test.txt");
std::cout << f1.getPath() << '\n';
std::cout << f1.getDir() << '\n';
Directory dir1("./../utility");
std::cout << dir1.getPath() << '\n';
return 0;
}
- Run the Example
./main
- Output
/a/b/c/d/file-system/test.txt
/a/b/c/d/file-system
/a/b/c/d/file-system/utility
File Class
- Path Operations:
getPath()
,getDir()
- File Management:
create()
,remove()
,copy()
,rename()
- Content Operations:
read()
,write()
,clear()
- Metadata:
exists()
,size()
,line()
,time()
Directory Class
- Path Operations:
getPath()
- Directory Management:
create()
,remove()
,rename()
,clear()
- Content Operations:
file()
,count()
,size()
,line()
- Static Utilities:
normalizePath()
,isAbsolutePath()
,mkdir()
,rmdir()
Contributions, bug reports, and feature requests are welcome! Feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.