dirutil.h
1/***************************************************************************
2 *
3 * Copyright (C) 2000-2025 by Willem van Straten
4 * Licensed under the Academic Free License version 2.1
5 *
6 ***************************************************************************/
7
8 #ifndef __DIRUTILS_H
9#define __DIRUTILS_H
10
11#ifdef __cplusplus
12
13#include <vector>
14#include <string>
15
16// in dirwith.C
17const std::string dirwith (double size, const std::vector<std::string>& disks,
18 const std::string& path=std::string(),
19 double usage_limit = 0.0,
20 double leave_free = 0.0);
21
22// in dirlist.C
23int dirlist (std::vector<std::string>* files, const char* path, bool all=false,
24 const char* pattern=NULL);
25int dirlist (std::vector<std::string>* files, const std::string& path, bool all=false,
26 const char* pattern=NULL);
27int dirlist (std::vector<std::string>* files, const std::vector<std::string>& paths,
28 bool all=false, const char* pattern=NULL);
29
30// in dirtree.C
31int dirtree (std::vector<std::string>* files, const char* path,
32 const char* pattern=NULL);
33int dirtree (std::vector<std::string>* files, const std::vector<std::string>& paths,
34 const char* pattern=NULL);
35
36// in dirglob.C
37bool is_glob_argument (const char* text);
38bool is_glob_argument (const std::string& text);
39
40extern std::string dirglob_program;
41
42void dirglob (std::vector<std::string>* filenames, const char* text);
43void dirglob (std::vector<std::string>* filenames, const std::string& text);
44
45// in dirglobtree.C
46// recursively follows directories
47void dirglobtree (std::vector<std::string>* filenames,
48 const std::string& root, const std::vector<std::string>& patterns);
49
50void dirglobtree (std::vector<std::string>* filenames,
51 const std::string& root, const std::string& pattern);
52
53// expands ~
54std::string expand (const std::string& filename);
55
56// returns the directory name (using std C dirname)
57std::string dirname (const std::string& path);
58
59// returns the file name (using std C basename)
60std::string basename (const std::string& path);
61
62extern "C" {
63#endif /* #ifdef __cplusplus */
64
65#include <inttypes.h>
66#include <sys/types.h>
67
68 /* recursively constructs a new directory named 'path' */
69 int makedir (const char* path);
70 /* resursively removes an existing directory named 'path' */
71 int removedir (const char* path);
72
73 /* returns the file modification time */
74 time_t file_mod_time (const char* filename);
75
76 /* returns true if the file exists */
77 int file_exists (const char* filename);
78
79 /* returns true if the file is a directory */
80 int file_is_directory (const char* filename);
81
82 /* returns the file size in bytes */
83 uint64_t filesize (const char* filename);
84
85#ifdef __cplusplus
86}
87#endif
88
89#endif

Generated using doxygen 1.14.0