|
MECO™ API Reference
|
[ CLASS ] - Operate on files. More...
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... | |
[ CLASS ] - Operate on files.
| def mFileSystem.fileLib.File.__init__ | ( | self, | |
path = None |
|||
| ) |
Constructor.
| path | [ str | None | in ] - Absolute path of a file. |
| N/A |
Reimplemented in mFileSystem.jsonFileLib.JSONFile, and mMecoSettings.appLib.AppFile.
| def mFileSystem.fileLib.File.__str__ | ( | self | ) |
String representation.
| N/A |
| def mFileSystem.fileLib.File.file | ( | self | ) |
| def mFileSystem.fileLib.File.directory | ( | self | ) |
Directory where the file is located in.
| N/A |
| def mFileSystem.fileLib.File.fileName | ( | self | ) |
Name of the file with it's extension.
| N/A |
| def mFileSystem.fileLib.File.baseName | ( | self | ) |
Name of the file without extension, base name.
| N/A |
| def mFileSystem.fileLib.File.extension | ( | self | ) |
| def mFileSystem.fileLib.File.size | ( | self | ) |
| def mFileSystem.fileLib.File.sizeStr | ( | self | ) |
| def mFileSystem.fileLib.File.content | ( | self | ) |
Content of the file.
| N/A |
| def mFileSystem.fileLib.File.asStr | ( | self | ) |
Get string representation.
| N/A |
Reimplemented in mMecoSettings.appLib.AppFile.
| def mFileSystem.fileLib.File.asDict | ( | self | ) |
Get file information as dict instance.
| N/A |
| def mFileSystem.fileLib.File.setFile | ( | self, | |
| path | |||
| ) |
Set file.
| path | [ str | None | in ] - Absolute path of a file. |
| N/A |
False is the file doesn't exist, True otherwise. Reimplemented in mMecoSettings.appLib.AppFile, mFileSystem.jsonFileLib.JSONFile, and mFileSystem.templateFileLib.TemplateFile.
| def mFileSystem.fileLib.File.update | ( | self | ) |
Update information of the file in case it has been altered.
| N/A |
| def mFileSystem.fileLib.File.exists | ( | self | ) |
Check whether the file exists.
| mFileSystem.exceptionLib.FileIsNotSet | - If no file is set. |
False is the file doesn't exist, True otherwise. | def mFileSystem.fileLib.File.rename | ( | self, | |
| newName | |||
| ) |
Rename the file.
| newName | [ str | None | in ] - New name of the file without the path. |
| mFileSystem.exceptionLib.FileAlreadyExists | - If a file with given newName already exists. |
| def mFileSystem.fileLib.File.copy | ( | self, | |
| destinationFile, | |||
overwrite = False |
|||
| ) |
Copy the file.
Method will create the destination path if it doesn't exist.
| destinationFile | [ str | None | in ] - Destination file with absolute path. |
| overwrite | [ bool | False | in ] - Whether to overwrite existing file. |
| mFileSystem.exceptionLib.FileDoesNotExist | - If source file doesn't exist. |
| mFileSystem.exceptionLib.FileAlreadyExists | - If destination file exists and overwrite argument provided False. |
| 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.
| destinationPath | [ str | None | in ] - Absolute path. |
| overwrite | [ bool | False | in ] - Whether to overwrite existing file. |
| mFileSystem.exceptionLib.FileDoesNotExist | - If source file doesn't exist. |
| mFileSystem.exceptionLib.FileAlreadyExists | - If destination file exists and overwrite argument provided False. |
| def mFileSystem.fileLib.File.remove | ( | self | ) |
Remove the file.
| N/A |
| def mFileSystem.fileLib.File.write | ( | self, | |
| line, | |||
append = True |
|||
| ) |
Write given line into the file.
| line | [ str | None | in ] - Line to be written. |
| append | [ bool | True | in ] - Whether the line will be appended. |
| N/A |
Reimplemented in mFileSystem.templateFileLib.TemplateFile.
| def mFileSystem.fileLib.File.writeLines | ( | self, | |
| lines, | |||
append = True |
|||
| ) |
Write given lines into the file.
| lines | [ list of str | None | in ] - Lines to be written. |
| append | [ bool | True | in ] - Whether the lines will be appended. |
| N/A |
| def mFileSystem.fileLib.File.read | ( | self | ) |
Read content of the file.
| N/A |
Reimplemented in mMecoSettings.appLib.AppFile, and mFileSystem.jsonFileLib.JSONFile.
| def mFileSystem.fileLib.File.readLines | ( | self | ) |
Read lines.
| N/A |
| def mFileSystem.fileLib.File.lineCount | ( | self | ) |
Get line count of the file.
| N/A |
|
static |
Check whether the given file exists.
| path | [ str | None | in ] - Absolute path of the file. |
| N/A |
|
static |
Get given byte size in human readable string.
| size | [ int | None | in ] - Size in bytes. |
| precision | [ int | 2 | in ] - Precision. |
| N/A |
|
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.
| path | [ str | None | in ] - File. |
| newExtension | [ str | None | in ] - New extension. |
| N/A |
| 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.
| 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. |
| IOError | - If absFile exists and overwrite argument is provided False. |
1.8.18