Skip to content
Merged
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
41 changes: 33 additions & 8 deletions src/Io.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
function setupfolder(folder_path::String)
if !isdir(folder_path)
mkdir(folder_path)
else
rm(folder_path,recursive=true)
mkdir(folder_path)
end
end
"""
Make sure the specified folder exists.

# Examples
setupfolder("output") # Remove everything inside "output"
setupfolder("output", ".*") # Remove everything inside "output"
setupfolder("output", "all") # Remove everything inside "output"
setupfolder("results", ".vtu") # Remove only .vtu files
setupfolder("results", [".vtu", ".pvd"]) # Remove multiple file types
setupfolder("data", nothing) # Keep existing contents
setupfolder("data", remove=nothing) # Keep existing contents
"""
function setupfolder(path::String; remove::Any="all")
if isdir(path)
cleandir(path, remove)
end
mkpath(path)
end

function cleandir(path::String, remove::String)
if remove === "all"
rm(path,recursive=true)
else
foreach(rm, filter(endswith(remove), readdir(path,join=true)))
end
end

function cleandir(path::String, remove::AbstractVector{String})
foreach(r -> cleandir(path,r), remove)
end

function cleandir(::String, ::Nothing)
end