MECO™ API Reference
Public Member Functions | Static Public Member Functions | List of all members
mFileSystem.fileLib.File Class Reference

[ CLASS ] - Operate on files. More...

Inheritance diagram for mFileSystem.fileLib.File:
mFileSystem.jsonFileLib.JSONFile mFileSystem.templateFileLib.TemplateFile mMecoSettings.appLib.AppFile

Public Member Functions

def __init__ (self, path=None)
 Constructor. More...
 
def __str__ (self)
 String representation. More...
 
def asStr (self)
 Get string representation. More...
 
def asDict (self)
 Get file information as dict instance. More...
 
def setFile (self, path)
 Set file. More...
 
def update (self)
 Update information of the file in case it has been altered. More...
 
def exists (self)
 Check whether the file exists. More...
 
def rename (self, newName)
 Rename the file. More...
 
def remove (self)
 Remove the file. More...
 
def create (cls, path, overwrite=False, binary=False)
 Create a file and return a mFileSystem.fileLib.File instance for it. More...
 
PROPERTIES
def file (self)
 Absolute path of the file. More...
 
def directory (self)
 Directory where the file is located in. More...
 
def fileName (self)
 Name of the file with it's extension. More...
 
def baseName (self)
 Name of the file without extension, base name. More...
 
def extension (self)
 File's extension. More...
 
def size (self)
 File size in bytes. More...
 
def sizeStr (self)
 File size as human readable string. More...
 
def content (self)
 Content of the file. More...
 
COPY
def copy (self, destinationFile, overwrite=False)
 Copy the file. More...
 
def copyToPath (self, destinationPath, overwrite=False)
 Copy the file to given path. More...
 
CONTENT
def write (self, line, append=True)
 Write given line into the file. More...
 
def writeLines (self, lines, append=True)
 Write given lines into the file. More...
 
def read (self)
 Read content of the file. More...
 
def readLines (self)
 Read lines. More...
 
def lineCount (self)
 Get line count of the file. More...
 

Static Public Member Functions

def fileExists (path)
 Check whether the given file exists. More...
 
def getFileSizeAsStr (size, precision=2)
 Get given byte size in human readable string. More...
 
def replaceExtension (path, newExtension)
 Replace given files extension with given extension. More...
 

Detailed Description

[ CLASS ] - Operate on files.

Constructor & Destructor Documentation

◆ __init__()

def mFileSystem.fileLib.File.__init__ (   self,
  path = None 
)

Constructor.

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

Reimplemented in mFileSystem.jsonFileLib.JSONFile, and mMecoSettings.appLib.AppFile.

Member Function Documentation

◆ __str__()

def mFileSystem.fileLib.File.__str__ (   self)

String representation.

Exceptions
N/A
Returns
str - String representation.

◆ file()

def mFileSystem.fileLib.File.file (   self)

Absolute path of the file.

Exceptions
N/A
Returns
str - File.

◆ directory()

def mFileSystem.fileLib.File.directory (   self)

Directory where the file is located in.

Exceptions
N/A
Returns
str - Directory.

◆ fileName()

def mFileSystem.fileLib.File.fileName (   self)

Name of the file with it's extension.

Exceptions
N/A
Returns
str - Value.

◆ baseName()

def mFileSystem.fileLib.File.baseName (   self)

Name of the file without extension, base name.

Exceptions
N/A
Returns
str - Base name.

◆ extension()

def mFileSystem.fileLib.File.extension (   self)

File's extension.

Exceptions
N/A
Returns
str - Extension.

◆ size()

def mFileSystem.fileLib.File.size (   self)

File size in bytes.

Exceptions
N/A
Returns
int - Size.

◆ sizeStr()

def mFileSystem.fileLib.File.sizeStr (   self)

File size as human readable string.

Exceptions
N/A
Returns
str - Human readable size.

◆ content()

def mFileSystem.fileLib.File.content (   self)

Content of the file.

Exceptions
N/A
Returns
str - If read method is used to read the content.
list fo str - If readLines method is used to read the content.

◆ asStr()

def mFileSystem.fileLib.File.asStr (   self)

Get string representation.

Exceptions
N/A
Returns
str - String representation.

Reimplemented in mMecoSettings.appLib.AppFile.

◆ asDict()

def mFileSystem.fileLib.File.asDict (   self)

Get file information as dict instance.

Exceptions
N/A
Returns
dict - Keys are; file, directory, fileName, baseName, extension, size, sizeStr.

◆ setFile()

def mFileSystem.fileLib.File.setFile (   self,
  path 
)

Set file.

Parameters
path[ str | None | in ] - Absolute path of a file.
Exceptions
N/A
Returns
bool - Result, returns False is the file doesn't exist, True otherwise.

Reimplemented in mMecoSettings.appLib.AppFile, mFileSystem.jsonFileLib.JSONFile, and mFileSystem.templateFileLib.TemplateFile.

◆ update()

def mFileSystem.fileLib.File.update (   self)

Update information of the file in case it has been altered.

Exceptions
N/A
Returns
bool - Result, returns False is the file doesn't exist.

◆ exists()

def mFileSystem.fileLib.File.exists (   self)

Check whether the file exists.

Exceptions
mFileSystem.exceptionLib.FileIsNotSet- If no file is set.
Returns
bool - Result, returns False is the file doesn't exist, True otherwise.

◆ rename()

def mFileSystem.fileLib.File.rename (   self,
  newName 
)

Rename the file.

Parameters
newName[ str | None | in ] - New name of the file without the path.
Exceptions
mFileSystem.exceptionLib.FileAlreadyExists- If a file with given newName already exists.
Returns
bool - Result.

◆ copy()

def mFileSystem.fileLib.File.copy (   self,
  destinationFile,
  overwrite = False 
)

Copy the file.

Method will create the destination path if it doesn't exist.

Parameters
destinationFile[ str | None | in ] - Destination file with absolute path.
overwrite[ bool | False | in ] - Whether to overwrite existing file.
Exceptions
mFileSystem.exceptionLib.FileDoesNotExist- If source file doesn't exist.
mFileSystem.exceptionLib.FileAlreadyExists- If destination file exists and overwrite argument provided False.
Returns
str - Absolute path of copied file.

◆ copyToPath()

def mFileSystem.fileLib.File.copyToPath (   self,
  destinationPath,
  overwrite = False 
)

Copy the file to given path.

File name will be intact.

Method will create the destination path if it doesn't exist.

Parameters
destinationPath[ str | None | in ] - Absolute path.
overwrite[ bool | False | in ] - Whether to overwrite existing file.
Exceptions
mFileSystem.exceptionLib.FileDoesNotExist- If source file doesn't exist.
mFileSystem.exceptionLib.FileAlreadyExists- If destination file exists and overwrite argument provided False.
Returns
str - Absolute path of the copied file.

◆ remove()

def mFileSystem.fileLib.File.remove (   self)

Remove the file.

Exceptions
N/A
Returns
bool - Result.

◆ write()

def mFileSystem.fileLib.File.write (   self,
  line,
  append = True 
)

Write given line into the file.

Parameters
line[ str | None | in ] - Line to be written.
append[ bool | True | in ] - Whether the line will be appended.
Exceptions
N/A
Returns
bool - Result.

Reimplemented in mFileSystem.templateFileLib.TemplateFile.

◆ writeLines()

def mFileSystem.fileLib.File.writeLines (   self,
  lines,
  append = True 
)

Write given lines into the file.

Parameters
lines[ list of str | None | in ] - Lines to be written.
append[ bool | True | in ] - Whether the lines will be appended.
Exceptions
N/A
Returns
bool - Result.

◆ read()

def mFileSystem.fileLib.File.read (   self)

Read content of the file.

See also
content
Exceptions
N/A
Returns
str - Content.
None - If file doesn't exist.

Reimplemented in mMecoSettings.appLib.AppFile, and mFileSystem.jsonFileLib.JSONFile.

◆ readLines()

def mFileSystem.fileLib.File.readLines (   self)

Read lines.

See also
content
Exceptions
N/A
Returns
list of str - Content.
None - If file doesn't exist.

◆ lineCount()

def mFileSystem.fileLib.File.lineCount (   self)

Get line count of the file.

Exceptions
N/A
Returns
int - Line count.

◆ fileExists()

def mFileSystem.fileLib.File.fileExists (   path)
static

Check whether the given file exists.

Parameters
path[ str | None | in ] - Absolute path of the file.
Exceptions
N/A
Returns
bool - Result.

◆ getFileSizeAsStr()

def mFileSystem.fileLib.File.getFileSizeAsStr (   size,
  precision = 2 
)
static

Get given byte size in human readable string.

Parameters
size[ int | None | in ] - Size in bytes.
precision[ int | 2 | in ] - Precision.
Exceptions
N/A
Returns
str - Size.

◆ replaceExtension()

def mFileSystem.fileLib.File.replaceExtension (   path,
  newExtension 
)
static

Replace given files extension with given extension.

Absolute or relative path of a file can be provided for absFile argument.

Method doesn't check whether the given absFile exists.

New extension will be added to absFile regardless it already has an extension.

Parameters
path[ str | None | in ] - File.
newExtension[ str | None | in ] - New extension.
Exceptions
N/A
Returns
str - File with new extension.

◆ create()

def mFileSystem.fileLib.File.create (   cls,
  path,
  overwrite = False,
  binary = False 
)

Create a file and return a mFileSystem.fileLib.File instance for it.

Directory, where the file will be created in, will be created if it doesn't exists.

Parameters
cls[ object | None | in ] - Class object.
path[ str | None | in ] - File name with absolute path.
overwrite[ bool | False | in ] - Whether existing file will be overwritten.
binary[ bool | False | in ] - Whether the file will be written in binary format.
Exceptions
IOError- If absFile exists and overwrite argument is provided False.
Returns
mFileSystem.fileLib.File - Instance of mFileSystem.fileLib.File class for created file.

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