xref: /4.0.0/platform/include/platform/dirutils.h (revision 877ba0c5)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2012 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#ifndef PLATFORM_DIRUTILS_H_
19#define PLATFORM_DIRUTILS_H_ 1
20
21#include <platform/visibility.h>
22
23#include <string>
24#include <vector>
25
26namespace CouchbaseDirectoryUtilities
27{
28    /**
29     * Return the directory part of an absolute path
30     */
31    PLATFORM_PUBLIC_API
32    std::string dirname(const std::string &dir);
33
34    /**
35     * Return the filename part of an absolute path
36     */
37    PLATFORM_PUBLIC_API
38    std::string basename(const std::string &name);
39
40    /**
41     * Return a vector containing all of the files starting with a given
42     * name stored in a given directory
43     */
44    PLATFORM_PUBLIC_API
45    std::vector<std::string> findFilesWithPrefix(const std::string &dir, const std::string &name);
46
47    /**
48     * Return a vector containing all of the files starting with a given
49     * name specified with this absolute path
50     */
51    PLATFORM_PUBLIC_API
52    std::vector<std::string> findFilesWithPrefix(const std::string &name);
53
54    /**
55     * Return a vector containing all of the files containing a given substring
56     * located in a given directory
57     */
58    PLATFORM_PUBLIC_API
59    std::vector<std::string> findFilesContaining(const std::string &dir, const std::string &name);
60
61    /**
62     * Delete a file or directory (including subdirectories)
63     */
64    PLATFORM_PUBLIC_API
65    bool rmrf(const std::string &path);
66
67
68    /**
69     * Check if a directory exists or not
70     */
71    PLATFORM_PUBLIC_API
72    bool isDirectory(const std::string &directory);
73}
74
75#endif  // PLATFORM_DIRUTILS_H_
76