DirTree CkPython Reference Documentation
CkDirTree
Current Version: 11.5.0
Chilkat.DirTree
Iterate through the contents of a base directory, either recursively or
one level at a time.
Get the current item's full path, relative path, UNC path, size, and
directory/file status.
Traverse entire directory trees when an application needs to process all
nested files and folders.
Limit iteration to the immediate contents of the base directory when
deeper traversal is not needed.
Use absolute or relative paths depending on whether the application needs
filesystem access or archive-style relative names.
Use
For an extended overview, see
DirTree Class Overview.
Iterate through files and subdirectories under a base directory.
Chilkat.DirTree is a lightweight directory-tree iterator for
traversing files and subdirectories under a selected base directory. It
supports recursive and non-recursive traversal and exposes useful information
about the current item, including absolute path, UNC path, relative path,
file size, and whether the current item is a directory.
Directory traversal
Current-item details
Recursive scanning
Non-recursive listing
Path-friendly output
Error-aware iteration
DoneIterating to distinguish normal completion from an
error when an iteration method returns false.
DoneIterating when iteration stops to determine whether traversal
completed normally or ended because of an error.
Object Creation
obj = chilkat.CkDirTree()
Properties
BaseDir
# ckStr is a CkString
dirTree.get_BaseDir(ckStr);
strVal = dirTree.baseDir();
dirTree.put_BaseDir(strVal);
DebugLogFilePath
# ckStr is a CkString
dirTree.get_DebugLogFilePath(ckStr);
strVal = dirTree.debugLogFilePath();
dirTree.put_DebugLogFilePath(strVal);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
DoneIterating
boolVal = dirTree.get_DoneIterating();
Set to True when the last file or sub-directory has been iterated.
FileSize32
intVal = dirTree.get_FileSize32();
The file size of the current file in the iteration. (0 if it is a directory.)
topFileSize64
int64Val = dirTree.get_FileSize64();
The file size as a 64-bit integer of the current file in the iteration. (0 if it is a directory.)
topFileSizeStr
# ckStr is a CkString
dirTree.get_FileSizeStr(ckStr);
strVal = dirTree.fileSizeStr();
The file size of the current file in the iteration as a decimal string. (0 if it is a directory.)
topFullPath
# ckStr is a CkString
dirTree.get_FullPath(ckStr);
strVal = dirTree.fullPath();
The absolute directory path of the current file or sub-directory.
topFullUncPath
# ckStr is a CkString
dirTree.get_FullUncPath(ckStr);
strVal = dirTree.fullUncPath();
The absolute UNC directory path of the current file or sub-directory.
topIsDirectory
boolVal = dirTree.get_IsDirectory();
True if the current position is a sub-directory, False if it is a file.
LastErrorHtml
# ckStr is a CkString
dirTree.get_LastErrorHtml(ckStr);
strVal = dirTree.lastErrorHtml();
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
# ckStr is a CkString
dirTree.get_LastErrorText(ckStr);
strVal = dirTree.lastErrorText();
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
# ckStr is a CkString
dirTree.get_LastErrorXml(ckStr);
strVal = dirTree.lastErrorXml();
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
boolVal = dirTree.get_LastMethodSuccess();
dirTree.put_LastMethodSuccess(boolVal);
Indicates the success or failure of the most recent method call: True means success, False means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Recurse
boolVal = dirTree.get_Recurse();
dirTree.put_Recurse(boolVal);
If True, the iteration will be recursive. If False the iteration is non-recursive. The default value is True.
RelativePath
# ckStr is a CkString
dirTree.get_RelativePath(ckStr);
strVal = dirTree.relativePath();
The relative directory path of the current file or sub-directory. (Relative to the BaseDir)
topUncommonOptions
# ckStr is a CkString
dirTree.get_UncommonOptions(ckStr);
strVal = dirTree.uncommonOptions();
dirTree.put_UncommonOptions(strVal);
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string, and should typically remain empty.
Q_EncodePathsAdded inv11.1.0. Return file paths Q-Encoded.
Utf8
boolVal = dirTree.get_Utf8();
dirTree.put_Utf8(boolVal);
When set to True, all string arguments and return values are interpreted as UTF-8 strings. When set to False, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is True. Before v11.0.0, it was False.
VerboseLogging
boolVal = dirTree.get_VerboseLogging();
dirTree.put_VerboseLogging(boolVal);
If set to True, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is False. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
Methods
AdvancePosition
Advances the current position in the directory tree traversal to the next file or sub-directory.
Important: If AdvancePosition returns False, it can be an error, or it could be that there are no more files and directories. To distinguish between the two cases, examine the DoneIterating property. If DoneIterating is True, then the False return value is not an error, but instead indicates that the end has been reached.
Returns True for success, False for failure.
BeginIterate
Begins a directory tree traversal. After calling this method, the various property values such as Fullpath, FileSize32, etc. can be retrieved for the 1st file / sub-directory in the traversal.
Important: If BeginIterate returns False, it can be an error, or it could be that there are 0 files and directories. To distinguish between the two cases, examine the DoneIterating property. If DoneIterating is True, then the False return value is not an error, but instead indicates 0 files/directories.
Returns True for success, False for failure.
top