uLib
User mode C/C++ extended API library for Win32 programmers.
|
#include <uLib/FileDir.h>
Directory entry. LIST_ENTRY descendant. Subject of DLinkList.
These entries are created by DirEntry::Scan(), via NewDirEntry().
Scan() is invoked by DirEntry::ScanDir(), which returns a directory tree.
Public Data | |
CSTR | Name |
PDLinkList | SubDir |
PDLinkList | Files |
PDirEntry | pParent |
PVOID | pData |
Public Data inherited from LIST_ENTRY | |
struct _LIST_ENTRY * | Flink |
struct _LIST_ENTRY * | Blink |
Static Public Attributes | |
static PFnDirAddAction | AddAction = NULL |
static PFnDirAction | DelAction = NULL |
static PFnAbortScan | Abort = NULL |
Public Functions | |
DirEntry (LPWIN32_FIND_DATA pFd, PDirEntry pParent=NULL, PScanDirCtx pCtx=NULL) | |
DirEntry (CSTR name, PDirEntry pParent=NULL, PScanDirCtx pCtx=NULL) | |
virtual | ~DirEntry () |
PDirEntry | AddSubDir (CSTR pzDir, PScanDirCtx pCtx) |
PFileEntry | AddFile (LPWIN32_FIND_DATA pFd, PScanDirCtx pCtx) |
bool | RemoveFromParent () |
UINT | GetFullPath (TSTR Buff, UINT BufLen) |
CSTR | GetName () |
UINT | GetBranchCount () |
UINT | GetFileCount () |
UINT64 | GetSizeOfFiles () |
UINT64 | GetSizeOfBranch () |
UINT | Scan (PScanDirCtx pCtx) |
Static Public Member Functions | |
static PDirEntry | ScanDir (CSTR BaseDir, UINT Depth=0, PDirEntry Parent=NULL, PUINT pCount=NULL, PScanDirCtx pCtx=NULL) |
static bool __stdcall | _delete (PLIST_ENTRY Entry, void *pData) |
static bool __stdcall | _dump (PLIST_ENTRY Entry, void *pData) |
DirEntry::DirEntry | ( | LPWIN32_FIND_DATA | pFd, |
PDirEntry | pParent = NULL , |
||
PScanDirCtx | pCtx = NULL |
||
) |
Normal constructor.
Definition at line 244 of file FileDir.cpp.
DirEntry::DirEntry | ( | CSTR | name, |
PDirEntry | pParent = NULL , |
||
PScanDirCtx | pCtx = NULL |
||
) |
Abbreviated constructor.
Definition at line 238 of file FileDir.cpp.
|
virtual |
Optionally calls your DelAction so you can perform any additional clean-up,
recursively disposes Files and SubDirs, and deallocates internal entry data.
Definition at line 253 of file FileDir.cpp.
|
static |
ScanDir() is the call point you use to obtain a recursive directory tree.
ScanDir returns a new DirEntry (or descendant) instance, or NULL on failure.
Do not forget to delete it when done.
See Scan() for further details on the scanning procedure.
BaseDir | Path to scan. |
Depth | Nr of directory levels (incl BaseDir) to scan. Zero == Use max. |
Parent | Parent directory. NULL for a root or other base directory. |
pCount | Optional. Returns accumulated file count. |
pCtx | Optional. Only needed in special or multi-thread cases. |
Definition at line 329 of file FileDir.cpp.
PDirEntry DirEntry::AddSubDir | ( | CSTR | pzDir, |
PScanDirCtx | pCtx | ||
) |
Add a DirEntry (or descendant) to SubDir. If SubDir is NULL, it is instanciated first.
Returns the result of the NewDirEntry callout.
Definition at line 699 of file FileDir.cpp.
PFileEntry DirEntry::AddFile | ( | LPWIN32_FIND_DATA | pFd, |
PScanDirCtx | pCtx | ||
) |
Add a FileEntry to this directory. If Files is NULL, it is instanciated first.
Returns the result of the NewFileEntry callout.
Definition at line 717 of file FileDir.cpp.
bool DirEntry::RemoveFromParent | ( | ) |
Remove this entry from it's containing DLinkList.
Return true on success.
Definition at line 728 of file FileDir.cpp.
UINT DirEntry::GetFullPath | ( | TSTR | Buff, |
UINT | BufLen | ||
) |
GetFullPath builds the full path (from BaseDir).
Returns nr of chars copied to the buffer, or 0 on failure.
Definition at line 585 of file FileDir.cpp.
CSTR DirEntry::GetName | ( | ) |
Get the terminal subpath.
(Since root/base directories may have composite names.)
Definition at line 537 of file FileDir.cpp.
UINT DirEntry::GetBranchCount | ( | ) |
Get recursive count of subdirectories.
Returns 0 if there are no subdirectories under this.
Definition at line 642 of file FileDir.cpp.
UINT DirEntry::GetFileCount | ( | ) |
Get recursive count of files.
Returns 0 if there are no files in the entire branch.
Definition at line 664 of file FileDir.cpp.
UINT64 DirEntry::GetSizeOfFiles | ( | ) |
Get accumulated size of contained files.
Returns 0 if there are no files in this directory.
Definition at line 677 of file FileDir.cpp.
UINT64 DirEntry::GetSizeOfBranch | ( | ) |
Get total recursive size of files in branch.
Returns 0 if there are no files in the entire branch.
Definition at line 692 of file FileDir.cpp.
UINT DirEntry::Scan | ( | PScanDirCtx | pCtx | ) |
Scan is the workhorse that traverses this and subdirectories recursively.
It is called by ScanDir, and returns the total file count found.
Note: Scan supports per-thread current directory to enable concurrent scanning.
Scan recursively scans the path specified in the constructor, to the depth specified in pCtx,
adding files and subdirectories to the appropriate lists.
The instanciation of entries are handled by NewDirEntry and NewFileEntry function pointers,
thus enabling polymorphism or entry filtering by using customized allocation functions.
In addition, new entries can have optional post-creation action functions invoked,
to perform additional initialization for custom entries.
Note: You normally don't call Scan directly, you call ScanDir()..
Scan is exposed for special cases, f.ex. if you need to do incremental scanning.
See also NewFileEntry, NewDirEntry, PFnDirAddAction, PFnFileAddAction, and PFnAbortScan.
Definition at line 448 of file FileDir.cpp.
|
static |
_delete is used to facilitate recursive deletion.
[internal] It deletes the instance, but doesn't remove it from the parent's SubDir list.
Definition at line 273 of file FileDir.cpp.
|
static |
DLinkList::ForEach callback to dump dir tree to debugger.
Definition at line 89 of file FileDir.cpp.
CSTR DirEntry::Name |
PDLinkList DirEntry::SubDir |
PDLinkList DirEntry::Files |
PDirEntry DirEntry::pParent |
PVOID DirEntry::pData |
|
static |
|
static |
|
static |