2019-12-19 03:24:12 +00:00
|
|
|
#ifndef cwFileSys_H
|
|
|
|
#define cwFileSys_H
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
2019-12-28 02:51:28 +00:00
|
|
|
namespace filesys
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
|
|
|
|
2019-12-28 02:51:28 +00:00
|
|
|
// Test the type of a file system object:
|
|
|
|
//
|
|
|
|
bool isDir( const char* dirStr ); //< Return true if 'dirStr' refers to an existing directory.
|
|
|
|
bool isFile( const char* fnStr ); //< Return true if 'fnStr' refers to an existing file.
|
|
|
|
bool isLink( const char* fnStr ); //< Return true if 'fnStr' refers to a symbolic link.
|
|
|
|
|
|
|
|
// Create File Names:
|
|
|
|
//
|
|
|
|
// Create a file name by concatenating sub-strings.
|
|
|
|
//
|
|
|
|
// Variable arg's. entries are directories inserted between
|
|
|
|
// 'dirPrefixStr' and the file name.
|
|
|
|
// Terminate var arg's directory list with a nullptr.
|
|
|
|
//
|
2020-04-20 19:01:21 +00:00
|
|
|
// The returned string must be released by a call to mem::release() or mem::free().
|
2019-12-28 02:51:28 +00:00
|
|
|
char* vMakeFn( const char* dir, const char* fn, const char* ext, va_list vl );
|
|
|
|
char* makeFn( const char* dir, const char* fn, const char* ext, ... );
|
|
|
|
|
|
|
|
|
2020-04-20 19:01:21 +00:00
|
|
|
char* expandPath( const char* dir );
|
|
|
|
|
|
|
|
|
2019-12-28 02:51:28 +00:00
|
|
|
// Parse a path into its parts:
|
|
|
|
//
|
|
|
|
// Return record used by pathParts()
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char* dirStr;
|
|
|
|
const char* fnStr;
|
|
|
|
const char* extStr;
|
|
|
|
} pathPart_t;
|
|
|
|
|
|
|
|
// Given a file name decompose it into a directory string, file name string and file extension string.
|
|
|
|
// The returned record and the strings it points to are contained in a single block of
|
|
|
|
// memory which must be released by a call to memRelease() or memFree()
|
|
|
|
pathPart_t* pathParts( const char* pathNameStr );
|
2019-12-28 04:35:39 +00:00
|
|
|
|
|
|
|
// Flags used by dirEntries 'includeFlags' parameter.
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kFileFsFl = 0x001, //< include all visible files
|
|
|
|
kDirFsFl = 0x002, //< include all visible directory
|
|
|
|
kLinkFsFl = 0x004, //< include all symbolic links
|
|
|
|
kInvisibleFsFl = 0x008, //< include file/dir name beginning with a '.'
|
|
|
|
kCurDirFsFl = 0x010, //< include '.' directory
|
|
|
|
kParentDirFsFl = 0x020, //< include '..' directory
|
|
|
|
|
|
|
|
kAllFsFl = 0x02f, //< all type flags
|
|
|
|
|
|
|
|
kFullPathFsFl = 0x040, //< return the full path in the 'name' field of dirEntry_t;
|
|
|
|
kRecurseFsFl = 0x080, //< recurse into directories
|
|
|
|
kRecurseLinksFsFl = 0x100 //< recurse into symbol link directories
|
|
|
|
};
|
|
|
|
|
|
|
|
// The return type for dirEntries().
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned flags; //< Entry type flags from kXXXFsFl.
|
|
|
|
const char* name; //< Entry name or full path depending on kFullPathFsFl.
|
|
|
|
} dirEntry_t;
|
|
|
|
|
|
|
|
// Return the file and directory names contained in a given subdirectory.
|
|
|
|
//
|
|
|
|
// Set 'includeFlags' with the kXXXFsFl flags of the files to include in the returned
|
|
|
|
// directory entry array. The value pointed to by dirEntryCntPtr will be set to the
|
|
|
|
// number of records in the returned array.
|
|
|
|
dirEntry_t* dirEntries( const char* dirStr, unsigned includeFlags, unsigned* dirEntryCntRef );
|
|
|
|
|
|
|
|
|
2019-12-28 02:51:28 +00:00
|
|
|
}
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|