The File class

class File

Bases: fs.Entry

copy(other, callback=None, callback_data=None)

Copy this file to another file or directory. If other is a directory, this file is copied into it, otherwise this file is copied over it.

Parameters:
  • other – anything accepted by entry()
  • callback – function receiving total size, total so far, callback_data
  • callback_data – passed to callback
Returns:

File object representing other

create(security=None)

Create this file optionally with specific security. If the file already exists it will not be overwritten.

Parameters:security – a security.Security object
Returns:this object
delete()

Delete this file

Returns:self
equals(other, compare_contents=False)

Is this file equal in size, dates and attributes to another. if compare_contents is True, use filecmp to compare the contents of the files.

Parameters:other – anything accepted by file()
Compare_contents :
 True to compare contents, False otherwise
Returns:True if the files are equal in size, modification date, attributes and contents

Create this file as a hard link from other

Parameters:other – anything accepted by file()
Returns:this File object

Create other as a hard link to this file.

Parameters:other – anything accepted by file()
Returns:File object corresponding to other
open_(mode='r', attributes=None, sec=None)

EXPERIMENTAL: Use the codecs.open function to open this file as a Python file object. Positional and keyword arguments are passed straight through to the codecs function.

Parameters:
  • mode – any of the usual Python modes
  • attributes – anything accepted by FILE_ATTRIBUTE
  • sec – anything accepted by Security.security()
touch(security=None)

Create this file optionally with specific security. If the file already exists it will not be overwritten.

Parameters:security – a security.Security object
Returns:this object
zip(zip_filename=<Unset>, mode='w', compression=8, allow_zip64=False)

Zip the file up into a zipfile. By default, the zipfile will have the name of the file with ”.zip” appended and will be a sibling of the file. Also by default a new zipfile will be created, overwriting any existing one, and standard compression will be used. The filename will be stored without any directory information.

A different zipfile can be specific as the zip_filename parameter, and this can be appended to (if it exists) by specifying “a” as the mode param.

Parameters:
  • zip_filename – The name of the resulting zipfile [this file with the extension changed to .zip]
  • mode – mode (usually “w”) to pass to the zipfile constructor
  • compression – compression level (usually DEFLATED)
  • allow_zip64 – passed to the zipfile constructor to allow > 2Gb files
Returns:

a File object corresponding to the zipfile created

Previous topic

The Entry class

Next topic

The Dir class

This Page