[ CLASS ] - Class to operate on directories.
More...
|
def | __init__ (self, directory=None) |
| Constructor. More...
|
|
|
def | directory (self) |
| Directory. More...
|
|
def | setDirectory (self, directory) |
| Set directory. More...
|
|
|
def | hasBeenSet (self) |
| Whether a directory has been set. More...
|
|
def | exists (self) |
| Whether the directory exists. More...
|
|
|
def | rename (self, newName) |
| Rename the directory. More...
|
|
def | remove (self) |
| Delete the current folder and everything inside it. More...
|
|
def | createFolder (self, folderName, setDirectory=True) |
| Create a folder in the directory. More...
|
|
|
def | getBaseName (self) |
| Get base name of the directory (name of the last folder of the directory). More...
|
|
|
def | listFolders (self, ignoreDot=True) |
| List folders. More...
|
|
def | listDirectories (self, ignoreDot=True) |
| List directories (with absolute path). More...
|
|
def | listDirectoriesRecursively (self, ignoreDot=True) |
| List directories recursively. More...
|
|
|
def | listFiles (self, ignoreDot=True, extension=None) |
| List files. More...
|
|
def | listFilesWithAbsolutePath (self, directory=None, ignoreDot=True, extension=None) |
| List files with absolute path. More...
|
|
def | listFilesRecursively (self, relative=False, extension=None, ignoreDot=True, ignoreExtensions=None) |
| List files including files under sub directories recursively. More...
|
|
|
def | split (directory) |
| Split given path by ignoring empty parts. More...
|
|
def | navigateUp (directory, level=1) |
| Navigate up by giving level. More...
|
|
def | create (directory) |
| Create a directory. More...
|
|
def | directoryExists (directory) |
| Check whether the given directory exists. More...
|
|
|
def | separator () |
| Get native separator. More...
|
|
def | addStartSeparator (directory) |
| Add separator at the start of the given directory. More...
|
|
def | addEndSeparator (directory) |
| Add separator at the end of the given directory. More...
|
|
def | removeStartSeparator (directory) |
| Remove separator at the beginning of the given directory. More...
|
|
def | removeEndSeparator (directory) |
| Remove separator at the end of the given directory. More...
|
|
def | toNativeSeparators (directory, startWithSeparator=True, endWithSeparator=False) |
| Convert separators in given directory to native separators. More...
|
|
|
def | join (directory, *directories) |
| Join given directories and make sure that right separator is used based on the current platform. More...
|
|
def | joinRelative (directory, *directories) |
| Join given directories and make sure that right separator is used based on the current platform. More...
|
|
|
def | listVersionedFolders (directory, absolutePath=False, version=mFileSystem.versionLib.Version.kLatest, semanticOnly=True, ignore=False, createPath=False) |
| List version folder(s) under given path. More...
|
|
def | listVersionedFiles (directory, absolutePath=False, version=mFileSystem.versionLib.Version.kLatest, extension=None, createPath=True) |
| List versioned file(s) under given path. More...
|
|
[ CLASS ] - Class to operate on directories.
◆ __init__()
def mFileSystem.directoryLib.Directory.__init__ |
( |
|
self, |
|
|
|
directory = None |
|
) |
| |
Constructor.
- Parameters
-
directory | [ str | None | in ] - Absolute path of a directory. |
- Exceptions
-
- Returns
- None - None.
◆ directory()
def mFileSystem.directoryLib.Directory.directory |
( |
|
self | ) |
|
Directory.
- Exceptions
-
- Returns
- str - Directory.
-
None - If a directory is not set previously.
◆ setDirectory()
def mFileSystem.directoryLib.Directory.setDirectory |
( |
|
self, |
|
|
|
directory |
|
) |
| |
Set directory.
- Parameters
-
directory | [ str | None | in ] - Absolute path of a directory. |
- Exceptions
-
- Returns
- bool - Returns False if directory doesn't exist.
◆ hasBeenSet()
def mFileSystem.directoryLib.Directory.hasBeenSet |
( |
|
self | ) |
|
Whether a directory has been set.
- Exceptions
-
- Returns
- bool - Result.
◆ exists()
def mFileSystem.directoryLib.Directory.exists |
( |
|
self | ) |
|
Whether the directory exists.
- Exceptions
-
- Returns
- bool - Result.
◆ rename()
def mFileSystem.directoryLib.Directory.rename |
( |
|
self, |
|
|
|
newName |
|
) |
| |
Rename the directory.
Method renames the last folder and sets it.
- Parameters
-
newName | [ str | None | in ] - New name of the directory. |
- Exceptions
-
- Returns
- bool - Returns False if a directory is not set previously or doesn't exist.
◆ remove()
def mFileSystem.directoryLib.Directory.remove |
( |
|
self | ) |
|
Delete the current folder and everything inside it.
Parent directory will be automatically set if deletion is successful.
- Exceptions
-
- Returns
- bool - Returns False if a directory is not set previously or doesn't exist.
◆ createFolder()
def mFileSystem.directoryLib.Directory.createFolder |
( |
|
self, |
|
|
|
folderName, |
|
|
|
setDirectory = True |
|
) |
| |
Create a folder in the directory.
You can use slash separated folders, i.e. folderOne/folderTwo for folderName
argument. Method returns True if a folder with folderName already exists.
- Parameters
-
folderName | [ str | None | in ] - Name of the folder. |
setDirectory | [ bool | None | in ] - Set newly created directory. |
- Exceptions
-
- Returns
- bool - Returns
False
if a directory is not set previously or doesn't exist.
◆ getBaseName()
def mFileSystem.directoryLib.Directory.getBaseName |
( |
|
self | ) |
|
Get base name of the directory (name of the last folder of the directory).
- Exceptions
-
- Returns
- str - Base name.
-
None - Returns None if a directory is not set previously or it doesn't exist.
◆ listFolders()
def mFileSystem.directoryLib.Directory.listFolders |
( |
|
self, |
|
|
|
ignoreDot = True |
|
) |
| |
List folders.
- Parameters
-
ignoreDot | [ bool | True | in ] - Ignore folders that start with dot (hidden folders). |
- Exceptions
-
- Returns
- list of str - Folders.
◆ listDirectories()
def mFileSystem.directoryLib.Directory.listDirectories |
( |
|
self, |
|
|
|
ignoreDot = True |
|
) |
| |
List directories (with absolute path).
- Parameters
-
ignoreDot | [ bool | True | in ] - Ignore directories that start with dot (hidden directories). |
- Exceptions
-
- Returns
- list of str - Directories.
◆ listDirectoriesRecursively()
def mFileSystem.directoryLib.Directory.listDirectoriesRecursively |
( |
|
self, |
|
|
|
ignoreDot = True |
|
) |
| |
List directories recursively.
- Parameters
-
ignoreDot | [ bool | True | in ] - Ignore directories that start with dot (hidden directories). |
- Exceptions
-
- Returns
- list of str - Directories.
-
None - Returns None if a directory is not set previously or doesn't exist.
◆ listFiles()
def mFileSystem.directoryLib.Directory.listFiles |
( |
|
self, |
|
|
|
ignoreDot = True , |
|
|
|
extension = None |
|
) |
| |
List files.
- Parameters
-
ignoreDot | [ bool | True | in ] - Ignore files that start with dot (hidden files). |
extension | [ str | None | in ] - Extension of the files that need to be listed. |
- Exceptions
-
- Returns
- list of str - Files.
-
None - Returns None if a directory is not set previously or doesn't exist.
◆ listFilesWithAbsolutePath()
def mFileSystem.directoryLib.Directory.listFilesWithAbsolutePath |
( |
|
self, |
|
|
|
directory = None , |
|
|
|
ignoreDot = True , |
|
|
|
extension = None |
|
) |
| |
List files with absolute path.
If you don't provide directory argument self directory will be used.
- Parameters
-
directory | [ str | None | in ] - Directory that will be searched. |
ignoreDot | [ bool | True | in ] - Ignore files that start with dot (hidden files). |
extension | [ str | None | in ] - Extension of the files that need to be found. |
- Exceptions
-
- Returns
- list of str - Files.
-
None - Returns None if a directory is not set previously or doesn't exist.
◆ listFilesRecursively()
def mFileSystem.directoryLib.Directory.listFilesRecursively |
( |
|
self, |
|
|
|
relative = False , |
|
|
|
extension = None , |
|
|
|
ignoreDot = True , |
|
|
|
ignoreExtensions = None |
|
) |
| |
List files including files under sub directories recursively.
All hidden directories and files will be ignored if you provide True for ignoreDot argument.
- Parameters
-
relative | [ bool | False | in ] - List files relative to the directory. |
extension | [ str | None | in ] - Extension of the files that need to be listed. |
ignoreDot | [ bool | True | in ] - Ignore files that start with dot (hidden files). |
ignoreExtensions | [ list | None | in ] - Extensions that will be ignored. |
- Exceptions
-
- Returns
- list of str - Files.
-
None - Returns None if a directory is not set previously or doesn't exist.
◆ split()
def mFileSystem.directoryLib.Directory.split |
( |
|
directory | ) |
|
|
static |
Split given path by ignoring empty parts.
- Parameters
-
- Exceptions
-
- Returns
- list of str - Directory.
◆ separator()
def mFileSystem.directoryLib.Directory.separator |
( |
| ) |
|
|
static |
Get native separator.
- Exceptions
-
- Returns
- str - Separator.
◆ addStartSeparator()
def mFileSystem.directoryLib.Directory.addStartSeparator |
( |
|
directory | ) |
|
|
static |
Add separator at the start of the given directory.
- Parameters
-
- Exceptions
-
- Returns
- str - Directory.
◆ addEndSeparator()
def mFileSystem.directoryLib.Directory.addEndSeparator |
( |
|
directory | ) |
|
|
static |
Add separator at the end of the given directory.
- Parameters
-
- Exceptions
-
- Returns
- str - Directory.
◆ removeStartSeparator()
def mFileSystem.directoryLib.Directory.removeStartSeparator |
( |
|
directory | ) |
|
|
static |
Remove separator at the beginning of the given directory.
- Parameters
-
- Exceptions
-
- Returns
- str - Directory.
◆ removeEndSeparator()
def mFileSystem.directoryLib.Directory.removeEndSeparator |
( |
|
directory | ) |
|
|
static |
Remove separator at the end of the given directory.
- Parameters
-
- Exceptions
-
- Returns
- str - Directory.
◆ toNativeSeparators()
def mFileSystem.directoryLib.Directory.toNativeSeparators |
( |
|
directory, |
|
|
|
startWithSeparator = True , |
|
|
|
endWithSeparator = False |
|
) |
| |
|
static |
Convert separators in given directory to native separators.
Separator will only be added at the beginning of the directory if startWithSeparator provided True and the platform is not Windows.
- Parameters
-
directory | [ str | None | in ] - Directory. |
startWithSeparator | [ bool | True | in ] - Add separator at the beginning. |
endWithSeparator | [ bool | False | in ] - Add separator at the end. |
- Exceptions
-
- Returns
- str - Directory.
◆ join()
def mFileSystem.directoryLib.Directory.join |
( |
|
directory, |
|
|
* |
directories |
|
) |
| |
|
static |
Join given directories and make sure that right separator is used based on the current platform.
- Parameters
-
directory | [ str, list, tuple | None | in ] - Directory. |
*directories | [ str | None | in ] - Directories. |
- Exceptions
-
- Returns
- str - Directory.
◆ joinRelative()
def mFileSystem.directoryLib.Directory.joinRelative |
( |
|
directory, |
|
|
* |
directories |
|
) |
| |
|
static |
Join given directories and make sure that right separator is used based on the current platform.
This method removes separator at the start and at the end of the joined directory.
- Parameters
-
directory | [ str, list, tuple | None | in ] - Directory. |
*directories | [ str | None | in ] - Directories. |
- Exceptions
-
- Returns
- str - Directory.
◆ navigateUp()
def mFileSystem.directoryLib.Directory.navigateUp |
( |
|
directory, |
|
|
|
level = 1 |
|
) |
| |
|
static |
Navigate up by giving level.
If '/somePath/with/someOther/folder' is provided, with level 2 the result would be '/somePath/with'
- Parameters
-
directory | [ str | None | in ] - Directory. |
level | [ int | 1 | in ] - How many times will be navigated up. |
- Exceptions
-
- Returns
- str - Directory.
◆ create()
def mFileSystem.directoryLib.Directory.create |
( |
|
directory | ) |
|
|
static |
◆ directoryExists()
def mFileSystem.directoryLib.Directory.directoryExists |
( |
|
directory | ) |
|
|
static |
Check whether the given directory exists.
- Parameters
-
- Exceptions
-
- Returns
- bool - Result.
◆ listVersionedFolders()
def mFileSystem.directoryLib.Directory.listVersionedFolders |
( |
|
directory, |
|
|
|
absolutePath = False , |
|
|
|
version = mFileSystem.versionLib.Version.kLatest , |
|
|
|
semanticOnly = True , |
|
|
|
ignore = False , |
|
|
|
createPath = False |
|
) |
| |
|
static |
List version folder(s) under given path.
This is a generic method which lists versioned folder(s) under given path.
Semantic version naming convention is 1.2.3 ([0-9]{1,}.[0-9]{1,}.[0-9]{1,})
Say you have three folders under a path, like;
The following results would occur for given version options.
Version Option | Lists |
sCore.versionLib.Version.kAll | All the folders |
sCore.versionLib.Version.kLatest | 3.0.0 |
sCore.versionLib.Version.kCurrent | 3.0.0 |
sCore.versionLib.Version.kFirst | 1.0.0 |
sCore.versionLib.Version.kLast | 3.0.0 |
sCore.versionLib.Version.kPrevious | 2.0.0 |
'2.0.0' | 2.0.0 |
'2.0.1' | None |
2 / '2' / '02' / '002' | None |
- Parameters
-
directory | [ str | None | in ] - Directory where the versioned folders are. |
absolutePath | [ bool | None | in ] - Whether to return absolute path of the versioned folders. |
version | [ enum, str | None | in ] - Requested version from sFileSystem.versionLib.Version class or a string that would match with the name of the versioned folder. |
semanticOnly | [ bool | None | in ] - Check semantic version, leave out any folder without semantic version naming convention. |
ignore | [ bool | False | in ] - Ignore if requested version doesn't exist and return the path of the version folder anyway. |
createPath | [ bool | True | in ] - Create given path if it doesn't exist. |
- Exceptions
-
- Returns
- None - If no versioned folder found.
-
str - Versioned folder.
-
list of str - If all versions are requested.
◆ listVersionedFiles()
List versioned file(s) under given path.
This is a generic method which lists versioned file(s) under given path.
Say you have three files under a path, like;
- file.v001.txt
- file.v002.txt
- file.v003.txt
The following results would occur for given version options.
Version Option | Lists |
mCore.versionLib.Version.kAll | All the files |
mCore.versionLib.Version.kLatest | file.v003.txt |
mCore.versionLib.Version.kCurrent | file.v003.txt |
mCore.versionLib.Version.kFirst | file.v001.txt |
mCore.versionLib.Version.kLast | file.v003.txt |
mCore.versionLib.Version.kPrevious | file.v002.txt |
2 / '2' / '02' / '002' | file.v002.txt |
- Parameters
-
directory | [ str | None | in ] - Directory where the versioned files are. |
absolutePath | [ bool | None | in ] - Whether to return absolute path of the versioned files. |
version | [ enum, str, int | None | in ] - Requested version from mFileSystem.versionLib.Version class, string or int that would match with the version of the file. |
extension | [ str | None | in ] - Extension of the files to be listed. |
createPath | [ bool | True | in ] - Create given path if it doesn't exist. |
- Exceptions
-
- Returns
- None - If no versioned file found.
-
str - Versioned file.
-
list of str - If all versions are requested via mCore.versionLib.Version.kAll.
The documentation for this class was generated from the following file: