uLib  User mode C/C++ extended API library for Win32 programmers.
DirEntry Class Reference

#include <uLib/FileDir.h>

Inheritance diagram for DirEntry:
LIST_ENTRY

Detailed Description

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.

Definition at line 268 of file FileDir.h.

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)
 

Constructor & Destructor Documentation

◆ DirEntry() [1/2]

DirEntry::DirEntry ( LPWIN32_FIND_DATA  pFd,
PDirEntry  pParent = NULL,
PScanDirCtx  pCtx = NULL 
)

Normal constructor.

Definition at line 244 of file FileDir.cpp.

◆ DirEntry() [2/2]

DirEntry::DirEntry ( CSTR  name,
PDirEntry  pParent = NULL,
PScanDirCtx  pCtx = NULL 
)

Abbreviated constructor.

Definition at line 238 of file FileDir.cpp.

◆ ~DirEntry()

DirEntry::~DirEntry ( )
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.

Member Function Documentation

◆ ScanDir()

PDirEntry DirEntry::ScanDir ( CSTR  BaseDir,
UINT  Depth = 0,
PDirEntry  Parent = NULL,
PUINT  pCount = NULL,
PScanDirCtx  pCtx = NULL 
)
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.

Parameters
BaseDirPath to scan.
DepthNr of directory levels (incl BaseDir) to scan. Zero == Use max.
ParentParent directory. NULL for a root or other base directory.
pCountOptional. Returns accumulated file count.
pCtxOptional. Only needed in special or multi-thread cases.

Definition at line 329 of file FileDir.cpp.

◆ AddSubDir()

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.

◆ AddFile()

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.

◆ RemoveFromParent()

bool DirEntry::RemoveFromParent ( )

Remove this entry from it's containing DLinkList.
Return true on success.

Definition at line 728 of file FileDir.cpp.

◆ GetFullPath()

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.

◆ GetName()

CSTR DirEntry::GetName ( )

Get the terminal subpath.
(Since root/base directories may have composite names.)

Definition at line 537 of file FileDir.cpp.

◆ GetBranchCount()

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.

◆ GetFileCount()

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.

◆ GetSizeOfFiles()

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.

◆ GetSizeOfBranch()

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.

◆ Scan()

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.

◆ _delete()

bool __stdcall DirEntry::_delete ( PLIST_ENTRY  Entry,
void *  pData 
)
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.

◆ _dump()

bool __stdcall DirEntry::_dump ( PLIST_ENTRY  Entry,
void *  pData 
)
static

DLinkList::ForEach callback to dump dir tree to debugger.

Definition at line 89 of file FileDir.cpp.

Member Data Documentation

◆ Name

CSTR DirEntry::Name

Directory pathname, w/o last backslash.

Definition at line 271 of file FileDir.h.

◆ SubDir

PDLinkList DirEntry::SubDir

NULL if no subdirectories.

Definition at line 275 of file FileDir.h.

◆ Files

PDLinkList DirEntry::Files

NULL if no files.

Definition at line 276 of file FileDir.h.

◆ pParent

PDirEntry DirEntry::pParent

Back pointer to parent directory, NULL if none.

Definition at line 278 of file FileDir.h.

◆ pData

PVOID DirEntry::pData

Arbitrary user data (e.g handled by Action).

Definition at line 279 of file FileDir.h.

◆ AddAction

PFnDirAddAction DirEntry::AddAction = NULL
static

Pointer to your action callback for added directories, or NULL.

Definition at line 285 of file FileDir.h.

◆ DelAction

PFnDirAction DirEntry::DelAction = NULL
static

Pointer to your action callback for destroying dir entries, or NULL.
Note: Caveat, DelAction gets a NULL pCtx (for technical reasons).

Definition at line 290 of file FileDir.h.

◆ Abort

PFnAbortScan DirEntry::Abort = NULL
static

Pointer to your abort sentry for recursive scan, or NULL.

Definition at line 294 of file FileDir.h.


The documentation for this class was generated from the following files: