BioDynaMo  v1.05.119-a4ff3934
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 <filesystem>
17 #include <string>
18 
19 namespace bdm {
20 
21 uint64_t RemoveDirectoryContents(const std::string& directory) {
22  std::filesystem::path dir = directory;
23  if (!std::filesystem::is_directory(dir) || std::filesystem::is_empty(dir)) {
24  return 0;
25  }
26  auto files_removed = std::filesystem::remove_all(directory);
27  std::filesystem::create_directory(directory);
28  // subtract 1 because we don't count the removal of `directory`
29  // itself.
30  return files_removed - 1;
31 }
32 
33 } // namespace bdm
filesystem.h
bdm
Definition: agent.cc:39
bdm::RemoveDirectoryContents
uint64_t RemoveDirectoryContents(const std::string &directory)
Definition: filesystem.cc:21