Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
filesystem_utils.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
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 
24 #ifndef FILESYSTEM_H
25 #define FILESYSTEM_H
26 
27 #include <time.h>
28 
29 #include "typedefs.h"
30 #include "linked_list.h"
32 
33 
39 typedef struct FileInformation
40 {
43 
45  size_t fi_size;
47 
48 
49 
50 #ifdef __cplusplus
51  extern "C" {
52 #endif
53 
54 
55 
64 
65 
75 GRASSROOTS_UTIL_API bool CalculateFileInformation (const char * const path_s, FileInformation *info_p);
76 
77 
88 GRASSROOTS_UTIL_API char *GetFilenameOnly (const char * const full_path_to_file_s);
89 
90 
101 GRASSROOTS_UTIL_API char *GetPathOnly (const char * const full_path_to_file_s);
102 
103 
118 GRASSROOTS_UTIL_API char *MakeFilename (const char * const path_s, const char * const filename_s);
119 
120 
121 
138 GRASSROOTS_UTIL_API bool DeterminePathAndFile (const char * const full_path_s, char ** const path_ss, char ** const filename_ss);
139 
140 
160 GRASSROOTS_UTIL_API char *SetFileExtension (const char * const filename_s, const char * const extension_s, bool replace_flag);
161 
162 
171 GRASSROOTS_UTIL_API void UsePlatformFileSeparator (char *value_s);
172 
173 
183 GRASSROOTS_UTIL_API bool IsPathValid (const char * const path_s);
184 
185 
195 GRASSROOTS_UTIL_API bool IsPathAbsolute (const char * const path_s);
196 
197 
209 GRASSROOTS_UTIL_API LinkedList *GetMatchingFiles (const char * const pattern_s, const bool full_path_flag);
210 
211 
223 
224 
236 
237 
248 GRASSROOTS_UTIL_API const char *GetParentDirectory (void);
249 
250 
261 GRASSROOTS_UTIL_API const char *GetPluginPattern (void);
262 
263 
274 GRASSROOTS_UTIL_API bool EnsureDirectoryExists (const char * const path_s);
275 
276 
289 GRASSROOTS_UTIL_API bool CopyToNewFile (const char * const src_filename_s, const char * const dest_filename_s, void (*callback_fn) (void));
290 
291 
301 GRASSROOTS_UTIL_API bool SetCurrentWorkingDirectory (const char * const path_s);
302 
303 
312 
313 
314 
324 
334 GRASSROOTS_UTIL_API bool IsDirectory (const char * const path_s);
335 
336 
346 GRASSROOTS_UTIL_API bool RemoveFile (const char * const path_s);
347 
348 
358 GRASSROOTS_UTIL_API bool DoesFileExist (const char * const path_s);
359 
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 
365 #endif /* FILESYSTEM_H */
grassroots_util_library.h
UsePlatformFileSeparator
void UsePlatformFileSeparator(char *value_s)
Replace any occurrences of // in a string with the platform-specific file separator.
FileInformation::fi_last_modified
time_t fi_last_modified
The timestamp of the last modification to a file.
Definition: filesystem_utils.h:42
SetCurrentWorkingDirectory
bool SetCurrentWorkingDirectory(const char *const path_s)
Set the current working directory.
GetFileSeparatorChar
char GetFileSeparatorChar(void)
Get the platform-specific file separator.
GetCurrentWorkingDirectory
char * GetCurrentWorkingDirectory(void)
Get the current working directory.
IsDirectory
bool IsDirectory(const char *const path_s)
Check whether the given path refers to a directory.
CopyToNewFile
bool CopyToNewFile(const char *const src_filename_s, const char *const dest_filename_s, void(*callback_fn)(void))
Copy the content of one file to another.
GetPathOnly
char * GetPathOnly(const char *const full_path_to_file_s)
Get the path to the parent directory only from a given path.
MakeFilename
char * MakeFilename(const char *const path_s, const char *const filename_s)
Construct a filename.
SetFileExtension
char * SetFileExtension(const char *const filename_s, const char *const extension_s, bool replace_flag)
Generate a new filename by adding an extension to a filename.
typedefs.h
GetPluginPattern
const char * GetPluginPattern(void)
Get the platform-specific string for the a plugin.
LinkedList
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
FileInformation
A datatype to hold a collection of metadata about a file.
Definition: filesystem_utils.h:39
FileInformation::InitFileInformation
void InitFileInformation(FileInformation *info_p)
Initialise a FileInformation ready for use.
GetHomeDirectory
char * GetHomeDirectory(void)
Get the current user's home directory.
EnsureDirectoryExists
bool EnsureDirectoryExists(const char *const path_s)
Makes sure that a given directory path exists.
DoesFileExist
bool DoesFileExist(const char *const path_s)
Check if a file/directory exists.
GetMatchingFiles
LinkedList * GetMatchingFiles(const char *const pattern_s, const bool full_path_flag)
Get files that match a given pattern.
IsPathValid
bool IsPathValid(const char *const path_s)
Check whether a given file/directory exists.
IsPathAbsolute
bool IsPathAbsolute(const char *const path_s)
Check whether a given path is absolute.
GetCurrentDirectoryString
const char * GetCurrentDirectoryString(void)
Get the platform-specific string for the current directory.
FileInformation::fi_size
size_t fi_size
The size of the file in bytes.
Definition: filesystem_utils.h:45
linked_list.h
A doubly-linked list.
DeterminePathAndFile
bool DeterminePathAndFile(const char *const full_path_s, char **const path_ss, char **const filename_ss)
Extract the parent path and filename only from a given path.
GetParentDirectory
const char * GetParentDirectory(void)
Get the platform-specific string for the parent directory.
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
GetFilenameOnly
char * GetFilenameOnly(const char *const full_path_to_file_s)
Get the filename only from a given path.
RemoveFile
bool RemoveFile(const char *const path_s)
Delete a file.
FileInformation::CalculateFileInformation
bool CalculateFileInformation(const char *const path_s, FileInformation *info_p)
Calculate the FileInformation for a given filename.