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

abstract IO More...

#include "ZFIODef_fwd.h"

Go to the source code of this file.

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 ZFIOTreePrint (const ZFPathInfo &pathInfo, const ZFOutput &outputCallback=(ZFOutputDefault()), const zfchar *headToken=(zft_zfnull), const zfchar *indentToken=(" "))
 list all files, usually for debug use
 
zfbool ZFIOForEach (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each child file or dir in specified pathInfo
 
zfbool ZFIOForEachFile (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each file, see ZFIOForEach
 
zfbool ZFIOForEachDir (const ZFPathInfo &pathInfo, const ZFListener &fileCallback, zfbool isRecursive=(_ZFT_t_zftrue))
 util method to loop each dir, see ZFIOForEach
 
zfbool ZFIOCopy (const ZFPathInfo &srcPath, const ZFPathInfo &dstPath, zfbool isRecursive=(_ZFT_t_zftrue), zfbool isForce=(_ZFT_t_zftrue))
 copy a file or directory from srcPath to dstPath
 

Detailed Description

abstract IO

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

◆ ZFIOForEach()

zfbool ZFIOForEach ( 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 ZFIOFindData &fd = zfargs.param1().to<v_ZFIOFindData *>()->zfv;
// do your things with the file
ZFIOForEach(pathInfo, fileCallback);
zfbool ZFIOForEach(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 ZFIO when finding files
Definition ZFIODef_fwd.h:71
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:34
type wrapper for ZFTypeId::Value
Definition ZFIODef_fwd.h:157
type wrapper for ZFTypeId::Value
Definition ZFTypeId_CoreType.h:437

fileCallback's sender would be the v_ZFIOFindData, param0 is v_ZFPathInfo that describe the child file or dir, and param1 is a v_zfstring stores the relative path to source pathInfo, set ZFArgs::eventFiltered to indicates process done

◆ ZFIOCopy()

zfbool ZFIOCopy ( const ZFPathInfo & srcPath,
const ZFPathInfo & dstPath,
zfbool isRecursive = (_ZFT_t_zftrue),
zfbool isForce = (_ZFT_t_zftrue) )
extern

copy a file or directory from srcPath to dstPath

if both src and dst exist, but one is file and another is dir, return zffalse
merge directory if dst is an existing dir (if isForce not set, would return false if dst has a child file with the same path in src)
override file if dst is an existing file and isForce is zftrue

Note
path must be well formed, use ZFPathFormat if necessary
always use read/write to copy files