Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added removeDirectory and getDirectorySize #1988

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions core/vibe/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ void removeFile(string path)
std.file.remove(path);
}

/**
Removes a directory including its files recursively
*/
void removeDirectory(Path path)
{
removeDirectory(path.toNativeString());
}
/// ditto
void removeDirectory(string path)
@trusted {
std.file.rmdirRecurse(path);
}

/**
Checks if a file exists
*/
Expand Down Expand Up @@ -261,6 +274,24 @@ FileInfo getFileInfo(string path)
return getFileInfo(Path(path));
}

/**
Sums up all file sizes recursively in a directory

Throws: A `FileException` is thrown if the file does not exist.
*/
size_t getDirectorySize(Path path)
{
return getDirectorySize(path.toNativeString());
}
/// ditto
size_t getDirectorySize(string path)
@trusted {
size_t total;
foreach( DirEntry ent; dirEntries(path, SpanMode.depth) )
total += makeFileInfo(ent).size;
return total;
}

/**
Creates a new directory.
*/
Expand Down