ONE - On-device Neural Engine
Loading...
Searching...
No Matches
filesystem_windows.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "filesystem.h"
18
19#include <direct.h>
20#include <windows.h>
21
22namespace filesystem
23{
24
25const std::string separator() { return "\\"; }
26
27std::string normalize_path(const std::string &path)
28{
29 std::string ret = path;
30
31 std::string candidate = "/";
32 size_t start_pos = 0;
33 while ((start_pos = ret.find(candidate, start_pos)) != std::string::npos)
34 {
35 ret.replace(start_pos, candidate.length(), separator());
36 start_pos += separator().length();
37 }
38 return ret;
39}
40
41bool is_dir(const std::string &path)
42{
43 DWORD ftyp = GetFileAttributesA(path.c_str());
44 if (ftyp == INVALID_FILE_ATTRIBUTES)
45 return false; // something is wrong with path
46
47 if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
48 return true; // this is a directory
49
50 return false; // this is not a directory
51}
52
53bool mkdir(const std::string &path) { return _mkdir(path.c_str()) == 0; }
54
55} // namespace filesystem
bool mkdir(const std::string &path)
bool is_dir(const std::string &path)
const std::string separator()
std::string normalize_path(const std::string &path)
Normalize compatible separator in path to default separator.