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

abstract IO More...

#include "ZFIODef.h"

Go to the source code of this file.

Functions

const zfstringZFPathType_file ()
 see ZFPathInfo
 
ZFInput ZFInputForFile (const zfstring &filePath)
 util to create a file input callback
 
ZFOutput ZFOutputForFile (const zfstring &filePath)
 util to create a file output callback
 
zfbool ZFFileIsExist (const zfstring &path)
 return true if file specified by path is exist
 
zfbool ZFFileIsDir (const zfstring &path)
 return true if file specified by path is a directory
 
zfbool ZFFilePathCreate (const zfstring &path, zfbool autoCreateParent=(_ZFT_t_zftrue))
 make directory
 
zfbool ZFFileRemove (const zfstring &path, zfbool isRecursive=(_ZFT_t_zftrue), zfbool isForce=(_ZFT_t_zftrue))
 delete a file or directory from srcPath to dstPath
 
zfbool ZFFileMove (const zfstring &srcPath, const zfstring &dstPath, zfbool isForce=(_ZFT_t_zftrue))
 move a file or directory from srcPath to dstPath
 
zfbool ZFFileFindFirst (ZFIOFindData &fd, const zfstring &path)
 find file or directory, similar to FindFirstFile under Windows
 
zfbool ZFFileFindNext (ZFIOFindData &fd)
 
void ZFFileFindClose (ZFIOFindData &fd)
 
void * ZFFileOpen (const zfstring &filePath, ZFIOOpenOptionFlags flags, zfbool autoCreateParent=(_ZFT_t_zftrue))
 open a file for read or write
 
zfbool ZFFileClose (void *token)
 close and save the file if need, return false if save failed
 
zfindex ZFFileRead (void *token, void *buf, zfindex maxByteSize)
 read file
 
zfindex ZFFileWrite (void *token, const void *src, zfindex maxByteSize=(((zfindex) -1)))
 write file, see ZFFileRead
 
zfbool ZFFileSeek (void *token, zfindex byteSize, ZFSeekPos seekPos=(ZFSeekPosBegin))
 similar to fseek, return false if seek out of range
 
zfindex ZFFileTell (void *token)
 get current file's position or zfindexMax() if error
 
zfindex ZFFileSize (void *token)
 util method to get file's total size (not left size)
 

Detailed Description

abstract IO

Function Documentation

◆ ZFPathType_file()

const zfstring & ZFPathType_file ( )
extern

see ZFPathInfo

pathData is the file path

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFInputForFile()

ZFInput ZFInputForFile ( const zfstring & filePath)
inline

util to create a file input callback

param:

  • (const zfstring &)filePath: file path to use

auto open and auto close files, may return a null callback if open file error
auto setup callback cache id with res file path

◆ ZFOutputForFile()

ZFOutput ZFOutputForFile ( const zfstring & filePath)
inline

util to create a file output callback

param:

  • (const zfstring &)filePath: file path to use

auto open and auto close files, may return a null callback if open file error

◆ ZFFileIsExist()

zfbool ZFFileIsExist ( const zfstring & path)
extern

return true if file specified by path is exist

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileIsDir()

zfbool ZFFileIsDir ( const zfstring & path)
extern

return true if file specified by path is a directory

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFilePathCreate()

zfbool ZFFilePathCreate ( const zfstring & path,
zfbool autoCreateParent = (_ZFT_t_zftrue) )
extern

make directory

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileRemove()

zfbool ZFFileRemove ( const zfstring & path,
zfbool isRecursive = (_ZFT_t_zftrue),
zfbool isForce = (_ZFT_t_zftrue) )
extern

delete a file or directory from srcPath to dstPath

fail if isRecursive is zffalse and dst is a dir

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileMove()

zfbool ZFFileMove ( const zfstring & srcPath,
const zfstring & dstPath,
zfbool isForce = (_ZFT_t_zftrue) )
extern

move a file or directory from srcPath to dstPath

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileFindFirst()

zfbool ZFFileFindFirst ( ZFIOFindData & fd,
const zfstring & path )
extern

find file or directory, similar to FindFirstFile under Windows

path supports path only, without wildcard support, e.g. "/path/" or "/path", "." and ".." won't be included
typical usage:

if(ZFFileFindFirst(fd, path)) {
do {
// do something
} while(ZFFileFindNext(fd));
}
zfbool ZFFileFindNext(ZFIOFindData &fd)
void ZFFileFindClose(ZFIOFindData &fd)
zfbool ZFFileFindFirst(ZFIOFindData &fd, const zfstring &path)
find file or directory, similar to FindFirstFile under Windows
data used by ZFIO when finding files
Definition ZFIODef_fwd.h:71
Returns
false if error or nothing found
Warning
strings in ZFIOFindData would be deleted after each findXXX call, you must save it if need future use
See also
ZFIOFindData, ZFFileFindFirst, ZFFileFindNext, ZFFileFindClose
Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileFindNext()

zfbool ZFFileFindNext ( ZFIOFindData & fd)
extern

◆ ZFFileFindClose()

void ZFFileFindClose ( ZFIOFindData & fd)
extern

◆ ZFFileOpen()

void * ZFFileOpen ( const zfstring & filePath,
ZFIOOpenOptionFlags flags,
zfbool autoCreateParent = (_ZFT_t_zftrue) )
extern

open a file for read or write

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFFileRead()

zfindex ZFFileRead ( void * token,
void * buf,
zfindex maxByteSize )
extern

read file

return size read, even if error occurred, typical usage:

zfindex sizeRead = 0;
while((sizeRead = ZFFileRead(token, buf)) > 0) {
// do something with buf
}
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
zfindex ZFFileRead(void *token, void *buf, zfindex maxByteSize)
read file

note that the tail '\0' won't be written to buf

Warning
ZFFile always read files in binary mode, for text files, you must make sure the file is UTF8 encoded without BOM

◆ ZFFileWrite()

zfindex ZFFileWrite ( void * token,
const void * src,
zfindex maxByteSize = (((zfindex) -1)) )
extern

write file, see ZFFileRead

return size written, even if error occurred, typical usage:

zfindex sizeWritten = ZFFileWrite(token, src, size);
if(sizeWritten != size) { // you can also check by sizeWritten
// write fail
}
zfindex ZFFileWrite(void *token, const void *src, zfindex maxByteSize=(((zfindex) -1)))
write file, see ZFFileRead


maxByteSize could be zfindexMax(), which means ZFFileWrite should be stopped when reached 0x00 in src, usually to output a UTF8 string

◆ ZFFileSize()

zfindex ZFFileSize ( void * token)
extern

util method to get file's total size (not left size)

ZFFileSeek to end, ZFFileTell, then ZFFileSeek to restore, return zfindexMax() if error
note that result is not ensured if file is opened in append mode