Stash Software API  2.0.0
Public Member Functions | Static Public Member Functions | List of all members
sFileSystem.directoryLib.Directory Class Reference

[ CLASS ] - Class to operate on directories. More...

Inheritance diagram for sFileSystem.directoryLib.Directory:

Public Member Functions

def __init__ (self, directory=None)
 Constructor. 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, directory=None, 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...
 
Properties
def directory (self)
 Directory. More...
 
def setDirectory (self, directory)
 Set directory. More...
 

Static Public Member Functions

def separator ()
 Get native separator. More...
 
def split (directory)
 Split given path by ignoring empty parts. 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 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 listVersionedFolders (directory, absPath=False, version=sFileSystem.versionLib.Version.kLatest, semantic=True, ignore=False, createPath=True)
 List version folder(s) under given path. More...
 
def listVersionedFiles (directory, absPath=False, version=sFileSystem.versionLib.Version.kLatest, extension=None, createPath=True)
 List versioned file(s) under given path. More...
 

Detailed Description

[ CLASS ] - Class to operate on directories.

Constructor & Destructor Documentation

◆ __init__()

def sFileSystem.directoryLib.Directory.__init__ (   self,
  directory = None 
)

Constructor.

Parameters
directory[ str | None | in ] - Absolute path of a directory.
Exceptions
N/A
Returns
None - None.

Member Function Documentation

◆ directory()

def sFileSystem.directoryLib.Directory.directory (   self)

Directory.

Exceptions
N/A
Returns
str - Directory.
None - If a directory is not set previously.

◆ setDirectory()

def sFileSystem.directoryLib.Directory.setDirectory (   self,
  directory 
)

Set directory.

Parameters
directory[ str | None | in ] - Absolute path of a directory.
Exceptions
N/A
Returns
bool - Returns False if directory doesn't exist.

◆ exists()

def sFileSystem.directoryLib.Directory.exists (   self)

Whether the directory exists.

Exceptions
sFileSystem.exceptionLib.DirectoryIsNotSet- If no directory is set.
Returns
bool - Result.

◆ rename()

def sFileSystem.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
sFileSystem.exceptionLib.DirectoryAlreadyExists- If a directory with given newName already exists.
Returns
bool - Returns False if a directory is not set previously or doesn't exist.

◆ remove()

def sFileSystem.directoryLib.Directory.remove (   self)

Delete the current folder and everything inside it.

Parent directory will be automatically set if deletion is successful.

Exceptions
N/A
Returns
bool - Returns False if a directory is not set previously or doesn't exist.

◆ createFolder()

def sFileSystem.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
N/A
Returns
bool - Returns False if a directory is not set previously or doesn't exist.

◆ getBaseName()

def sFileSystem.directoryLib.Directory.getBaseName (   self)

Get base name of the directory (name of the last folder of the directory).

Exceptions
N/A
Returns
str - Base name.
None - Returns None if a directory is not set previously or it doesn't exist.

◆ listFolders()

def sFileSystem.directoryLib.Directory.listFolders (   self,
  ignoreDot = True 
)

List folders.

Parameters
ignoreDot[ bool | True | in ] - Ignore folders that start with dot (hidden folders).
Exceptions
N/A
Returns
list of str - Folders.
None - Returns None if a directory is not set previously or doesn't exist.

◆ listDirectories()

def sFileSystem.directoryLib.Directory.listDirectories (   self,
  directory = None,
  ignoreDot = True 
)

List directories (with absolute path).

Parameters
directory[ str | None | in ] - Absolute path of the directory.
ignoreDot[ bool | True | in ] - Ignore directories that start with dot (hidden directories).
Exceptions
N/A
Returns
list of str - Directories.
None - Returns None if a directory is not set previously or doesn't exist.

◆ listDirectoriesRecursively()

def sFileSystem.directoryLib.Directory.listDirectoriesRecursively (   self,
  ignoreDot = True 
)

List directories recursively.

Parameters
ignoreDot[ bool | True | in ] - Ignore directories that start with dot (hidden directories).
Exceptions
N/A
Returns
list of str - Directories.
None - Returns None if a directory is not set previously or doesn't exist.

◆ listFiles()

def sFileSystem.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
N/A
Returns
list of str - Files.
None - Returns None if a directory is not set previously or doesn't exist.

◆ listFilesWithAbsolutePath()

def sFileSystem.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
N/A
Returns
list of str - Files.
None - Returns None if a directory is not set previously or doesn't exist.

◆ listFilesRecursively()

def sFileSystem.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
N/A
Returns
list of str - Files.
None - Returns None if a directory is not set previously or doesn't exist.

◆ separator()

def sFileSystem.directoryLib.Directory.separator ( )
static

Get native separator.

Exceptions
N/A
Returns
str - Separator.

◆ split()

def sFileSystem.directoryLib.Directory.split (   directory)
static

Split given path by ignoring empty parts.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
list of str - Splitted directory.

◆ addStartSeparator()

def sFileSystem.directoryLib.Directory.addStartSeparator (   directory)
static

Add separator at the start of the given directory.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
str - Directory.

◆ addEndSeparator()

def sFileSystem.directoryLib.Directory.addEndSeparator (   directory)
static

Add separator at the end of the given directory.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
str - Directory.

◆ removeStartSeparator()

def sFileSystem.directoryLib.Directory.removeStartSeparator (   directory)
static

Remove separator at the beginning of the given directory.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
str - Directory.

◆ removeEndSeparator()

def sFileSystem.directoryLib.Directory.removeEndSeparator (   directory)
static

Remove separator at the end of the given directory.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
str - Directory.

◆ toNativeSeparators()

def sFileSystem.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
N/A
Returns
str - Directory.

◆ join()

def sFileSystem.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
N/A
Returns
str - Directory.

◆ joinRelative()

def sFileSystem.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
N/A
Returns
str - Directory.

◆ navigateUp()

def sFileSystem.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
N/A
Returns
str - Directory.

◆ create()

def sFileSystem.directoryLib.Directory.create (   directory)
static

Create a directory.

sFileSystem.directoryLib.Directory class instance will be returned for the directory whether it was exists or newly created.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
sFileSystem.directoryLib.Directory - Instance of sFileSystem.directoryLib.Directory class.

◆ directoryExists()

def sFileSystem.directoryLib.Directory.directoryExists (   directory)
static

Check whether the given directory exists.

Parameters
directory[ str | None | in ] - Directory.
Exceptions
N/A
Returns
bool - Result.

◆ listVersionedFolders()

def sFileSystem.directoryLib.Directory.listVersionedFolders (   directory,
  absPath = False,
  version = sFileSystem.versionLib.Version.kLatest,
  semantic = True,
  ignore = False,
  createPath = True 
)
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;

  • 1.0.0
  • 2.0.0
  • 3.0.0

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.
absPath[ 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.
semantic[ 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
N/A
Returns
None - If no versioned folder found.
str - Versioned folder.
list of str - If all versions are requested.

◆ listVersionedFiles()

def sFileSystem.directoryLib.Directory.listVersionedFiles (   directory,
  absPath = False,
  version = sFileSystem.versionLib.Version.kLatest,
  extension = None,
  createPath = True 
)
static

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
sCore.versionLib.Version.kAll All the files
sCore.versionLib.Version.kLatest file.v003.txt
sCore.versionLib.Version.kCurrent file.v003.txt
sCore.versionLib.Version.kFirst file.v001.txt
sCore.versionLib.Version.kLast file.v003.txt
sCore.versionLib.Version.kPrevious file.v002.txt
2 / '2' / '02' / '002' file.v002.txt
Parameters
directory[ str | None | in ] - Directory where the versioned files are.
absPath[ bool | None | in ] - Whether to return absolute path of the versioned files.
version[ enum, str, int | None | in ] - Requested version from sFileSystem.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
N/A
Returns
None - If no versioned file found.
str - Versioned file.
list of str - If all versions are requested via sCore.versionLib.Version.kAll.

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