BioDynaMo  v1.03.58-27764645
filesystem.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #include "core/util/filesystem.h"
16 #include <experimental/filesystem>
17 #include <string>
18 
19 namespace fs = std::experimental::filesystem;
20 
21 namespace bdm {
22 
23 uint64_t RemoveDirectoryContents(const std::string& directory) {
24  fs::path dir = directory;
25  if (!fs::is_directory(dir) || fs::is_empty(dir)) {
26  return 0;
27  }
28  auto files_removed = fs::remove_all(directory);
29  fs::create_directory(directory);
30  // subtract 1 because we don't count the removal of `directory`
31  // itself.
32  return files_removed - 1;
33 }
34 
35 } // namespace bdm
filesystem.h
bdm
Definition: agent.cc:39
bdm::RemoveDirectoryContents
uint64_t RemoveDirectoryContents(const std::string &directory)
Definition: filesystem.cc:23