ZFFramework
 
Loading...
Searching...
No Matches
ZFFile_util.h File Reference

file utility More...

#include "ZFFile_file.h"
#include "ZFFile_res.h"
#include "ZFFile_pathInfo.h"

Go to the source code of this file.

Macros

#define ZFFileCloseHolder(token)
 util method to call ZFFileClose after code block
 
#define ZFResCloseHolder(token)
 util method to call ZFResClose after code block
 
#define ZFPathInfoCloseHolder(pathInfo, token)
 util method to call ZFPathInfoClose after code block
 

Functions

zfbool ZFPathFormatT (zfstring &ret, const zfchar *src, zfindex srcLen=(((zfindex) -1)))
 format path
 
zfstring ZFPathFormat (const zfchar *src, zfindex srcLen=(((zfindex) -1)))
 see ZFPathFormatT
 
zfbool ZFPathFormatRelativeT (zfstring &ret, const zfchar *src, zfindex srcLen=(((zfindex) -1)))
 util method to resolve ".." in path
 
zfstring ZFPathFormatRelative (const zfchar *src, zfindex srcLen=(((zfindex) -1)))
 see ZFPathFormatRelativeT
 
zfbool ZFFileNameOfT (zfstring &ret, const zfchar *src)
 get file name from path or src if error, e.g. "file.ext" from "/path/file.ext"
 
zfstring ZFFileNameOf (const zfchar *src)
 see ZFFileNameOfT
 
zfbool ZFFileNameOfWithoutExtT (zfstring &ret, const zfchar *src)
 get file name without extension from path or src if error, e.g. "file.ext0" from "/path/file.ext0.ext1"
 
zfstring ZFFileNameOfWithoutExt (const zfchar *src)
 see ZFFileNameOfWithoutExtT
 
zfbool ZFFileExtOfT (zfstring &ret, const zfchar *src)
 get file extension from path or empty if error, e.g. "ext1" from "/path/file.ext0.ext1", or empty if no extension
 
zfstring ZFFileExtOf (const zfchar *src)
 see ZFFileExtOfT
 
zfbool ZFPathOfWithoutExtT (zfstring &ret, const zfchar *src)
 get file path without ext, e.g. "/path/file.ext0" from "/path/file.ext0.ext1", or original string if no extension
 
zfstring ZFPathOfWithoutExt (const zfchar *src)
 see ZFPathOfWithoutExtT
 
zfbool ZFPathOfWithoutAllExtT (zfstring &ret, const zfchar *src)
 get file path without all ext, e.g. "/path/file" from "/path/file.ext0.ext1", or original string if no extension
 
zfstring ZFPathOfWithoutAllExt (const zfchar *src)
 see ZFPathOfWithoutAllExtT
 
zfbool ZFPathParentOfT (zfstring &ret, const zfchar *src)
 get parent path
 
zfstring ZFPathParentOf (const zfchar *src)
 see ZFPathParentOfT
 
zfbool ZFPathComponentsOfT (ZFCoreArray< zfstring > &ret, const zfchar *src)
 get each file components from path or empty if error, e.g. {"path", "file.ext"}(as array) from "/path/file.ext"
 
ZFCoreArray< zfstringZFPathComponentsOf (const zfchar *src)
 see ZFPathComponentsOfT
 
void ZFPathInfoTreePrint (const ZFPathInfo &pathInfo, const ZFOutput &outputCallback=(ZFOutputDefault()), const zfchar *headToken=(zft_zfnull), const zfchar *indentToken=(" "))
 list all files, usually for debug use
 
zfbool ZFPathInfoForEach (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each child file or dir in specified pathInfo
 
zfbool ZFPathInfoForEachFile (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each file, see ZFPathInfoForEach
 
zfbool ZFPathInfoForEachDir (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each dir, see ZFPathInfoForEach
 

Detailed Description

file utility

Function Documentation

◆ ZFPathFormatT()

zfbool ZFPathFormatT ( zfstring & ret,
const zfchar * src,
zfindex srcLen = (((zfindex) -1)) )
extern

format path

format rules:

  • ensured no '/' at tail (except for xxx://)
  • all extra '/' and '\' would be replaced with single '/' (except for xxx://)
  • strip spaces and tabs at head and tail
  • replace these escape chars:
    • '"' to double quote
    • '\ ' to space
  • remove "./" at head
  • remove "/." at tail
  • remove "/./" at anywhere
  • null src is treated as error, while empty string src is not an error
  • single "/" src would result empty string

◆ ZFFileNameOfT()

zfbool ZFFileNameOfT ( zfstring & ret,
const zfchar * src )
extern

get file name from path or src if error, e.g. "file.ext" from "/path/file.ext"

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileNameOfWithoutExtT()

zfbool ZFFileNameOfWithoutExtT ( zfstring & ret,
const zfchar * src )
extern

get file name without extension from path or src if error, e.g. "file.ext0" from "/path/file.ext0.ext1"

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileExtOfT()

zfbool ZFFileExtOfT ( zfstring & ret,
const zfchar * src )
extern

get file extension from path or empty if error, e.g. "ext1" from "/path/file.ext0.ext1", or empty if no extension

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFPathOfWithoutExtT()

zfbool ZFPathOfWithoutExtT ( zfstring & ret,
const zfchar * src )
extern

get file path without ext, e.g. "/path/file.ext0" from "/path/file.ext0.ext1", or original string if no extension

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFPathOfWithoutAllExtT()

zfbool ZFPathOfWithoutAllExtT ( zfstring & ret,
const zfchar * src )
extern

get file path without all ext, e.g. "/path/file" from "/path/file.ext0.ext1", or original string if no extension

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFPathParentOfT()

zfbool ZFPathParentOfT ( zfstring & ret,
const zfchar * src )
extern

get parent path

return empty string if no parent found

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFPathComponentsOfT()

zfbool ZFPathComponentsOfT ( ZFCoreArray< zfstring > & ret,
const zfchar * src )
extern

get each file components from path or empty if error, e.g. {"path", "file.ext"}(as array) from "/path/file.ext"

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFPathInfoForEach()

zfbool ZFPathInfoForEach ( const ZFPathInfo & pathInfo,
const ZFListener & fileCallback,
zfbool isRecursive = (_ZFT_t_zftrue) )
extern

util method to loop each child file or dir in specified pathInfo

usage:

ZFLISTENER(fileCallback) {
const ZFPathInfo &pathInfo = zfargs.param0().to<v_ZFPathInfo *>()->zfv;
const ZFFileFindData &fd = zfargs.param1().to<v_ZFFileFindData *>()->zfv;
// do your things with the file
ZFPathInfoForEach(pathInfo, fileCallback);
zfbool ZFPathInfoForEach(const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
util method to loop each child file or dir in specified pathInfo
#define ZFLISTENER(name)
util to declare a ZFListener locally
Definition ZFListenerDeclare.h:53
#define ZFLISTENER_END()
see ZFLISTENER
Definition ZFListenerDeclare.h:17
data used by ZFFile when finding files
Definition ZFFile_fwd.h:53
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:35
type wrapper for ZFTypeId::Value
Definition ZFFile_fwd.h:139
type wrapper for ZFTypeId::Value
Definition ZFTypeId_CoreType.h:472

fileCallback's param0 is v_ZFPathInfo that describe the child file or dir, and param1 is v_ZFFileFindData, set ZFArgs::eventFiltered to indicates process done