[ CLASS ] - Operate on files.
More...
|
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...
|
|
|
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...
|
|
|
def | copy (self, destinationFile, overwrite=False) |
| Copy the file. More...
|
|
def | copyToPath (self, destinationPath, overwrite=False) |
| Copy the file to given path. More...
|
|
|
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...
|
|
[ CLASS ] - Operate on files.
◆ __init__()
def mMeco.fileSystem.fileLib.File.__init__ |
( |
|
self, |
|
|
|
path = None |
|
) |
| |
Constructor.
- Parameters
-
path | [ str | None | in ] - Absolute path of a file. |
- Exceptions
-
- Returns
- None - None.
◆ __str__()
def mMeco.fileSystem.fileLib.File.__str__ |
( |
|
self | ) |
|
String representation.
- Exceptions
-
- Returns
- str - String representation.
◆ file()
def mMeco.fileSystem.fileLib.File.file |
( |
|
self | ) |
|
Absolute path of the file.
- Exceptions
-
- Returns
- str - File.
◆ directory()
def mMeco.fileSystem.fileLib.File.directory |
( |
|
self | ) |
|
Directory where the file is located in.
- Exceptions
-
- Returns
- str - Directory.
◆ fileName()
def mMeco.fileSystem.fileLib.File.fileName |
( |
|
self | ) |
|
Name of the file with it's extension.
- Exceptions
-
- Returns
- str - Value.
◆ baseName()
def mMeco.fileSystem.fileLib.File.baseName |
( |
|
self | ) |
|
Name of the file without extension, base name.
- Exceptions
-
- Returns
- str - Base name.
◆ extension()
def mMeco.fileSystem.fileLib.File.extension |
( |
|
self | ) |
|
File's extension.
- Exceptions
-
- Returns
- str - Extension.
◆ size()
def mMeco.fileSystem.fileLib.File.size |
( |
|
self | ) |
|
File size in bytes.
- Exceptions
-
- Returns
- int - Size.
◆ sizeStr()
def mMeco.fileSystem.fileLib.File.sizeStr |
( |
|
self | ) |
|
File size as human readable string.
- Exceptions
-
- Returns
- str - Human readable size.
◆ content()
def mMeco.fileSystem.fileLib.File.content |
( |
|
self | ) |
|
Content of the file.
- Exceptions
-
- 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 mMeco.fileSystem.fileLib.File.asStr |
( |
|
self | ) |
|
Get string representation.
- Exceptions
-
- Returns
- str - String representation.
◆ asDict()
def mMeco.fileSystem.fileLib.File.asDict |
( |
|
self | ) |
|
Get file information as dict instance.
- Exceptions
-
- Returns
- dict - Keys are; file, directory, fileName, baseName, extension, size, sizeStr.
◆ setFile()
def mMeco.fileSystem.fileLib.File.setFile |
( |
|
self, |
|
|
|
path |
|
) |
| |
Set file.
- Parameters
-
path | [ str | None | in ] - Absolute path of a file. |
- Exceptions
-
- Returns
- bool - Result, returns
False
is the file doesn't exist, True
otherwise.
◆ update()
def mMeco.fileSystem.fileLib.File.update |
( |
|
self | ) |
|
Update information of the file in case it has been altered.
- Exceptions
-
- Returns
- bool - Result, returns False is the file doesn't exist.
◆ exists()
def mMeco.fileSystem.fileLib.File.exists |
( |
|
self | ) |
|
Check whether the file exists.
- Exceptions
-
- Returns
- bool - Result, returns
False
is the file doesn't exist, True
otherwise.
◆ rename()
def mMeco.fileSystem.fileLib.File.rename |
( |
|
self, |
|
|
|
newName |
|
) |
| |
Rename the file.
- Parameters
-
newName | [ str | None | in ] - New name of the file without the path. |
- Exceptions
-
- Returns
- bool - Result.
◆ copy()
def mMeco.fileSystem.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
-
- Returns
- str - Absolute path of copied file.
◆ copyToPath()
def mMeco.fileSystem.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
-
- Returns
- str - Absolute path of the copied file.
◆ remove()
def mMeco.fileSystem.fileLib.File.remove |
( |
|
self | ) |
|
Remove the file.
- Exceptions
-
- Returns
- bool - Result.
◆ write()
def mMeco.fileSystem.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
-
- Returns
- bool - Result.
◆ writeLines()
def mMeco.fileSystem.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
-
- Returns
- bool - Result.
◆ read()
def mMeco.fileSystem.fileLib.File.read |
( |
|
self | ) |
|
Read content of the file.
- See also
- content
- Exceptions
-
- Returns
- str - Content.
-
None - If file doesn't exist.
◆ readLines()
def mMeco.fileSystem.fileLib.File.readLines |
( |
|
self | ) |
|
Read lines.
- See also
- content
- Exceptions
-
- Returns
- list of str - Content.
-
None - If file doesn't exist.
◆ lineCount()
def mMeco.fileSystem.fileLib.File.lineCount |
( |
|
self | ) |
|
Get line count of the file.
- Exceptions
-
- Returns
- int - Line count.
◆ fileExists()
def mMeco.fileSystem.fileLib.File.fileExists |
( |
|
path | ) |
|
|
static |
Check whether the given file exists.
- Parameters
-
path | [ str | None | in ] - Absolute path of the file. |
- Exceptions
-
- Returns
- bool - Result.
◆ getFileSizeAsStr()
def mMeco.fileSystem.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
-
- Returns
- str - Size.
◆ replaceExtension()
def mMeco.fileSystem.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
-
- Returns
- str - File with new extension.
◆ create()
def mMeco.fileSystem.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: