File

class cgp_generic_utils.files.File(path)

Bases: cgp_generic_utils.files.Path

file object that manipulates any kind of file on the file system

copy(destinationDirectory=None, destinationName=None)

copy the file

Parameters:
  • destinationDirectory (str or cgp_generic_utils.files.Directory) – directory where the copied file will be saved - If None, same as original
  • destinationName (str) – name of the copied file - If None, same as original - ! HAS TO BE WITHOUT EXTENSION !
Returns:

the copied file

Return type:

cgp_generic_utils.files.File

classmethod create(path, content=None, **__)

create the file

Parameters:
  • path (str) – path of the file
  • content (any) – content of the file
Returns:

the created file

Return type:

cgp_generic_utils.files.File

evaluate(asLiteral=True)

evaluate the content of the file

Parameters:asLiteral (bool) – True : content evaluated with ast.literal_eval - False : content evaluated with eval
Returns:the evaluated content of the file
Return type:any
execute()

execute the content of the file

Returns:the executed content of the file
Return type:any
open()

open the file in the script editor

read()

read the file

Returns:the content of the file
Return type:any
write(content)

write data in the specified path file

Parameters:content (any) – content to write in the file