module filehelper.anyfhelper

Short summary

module pyquickhelper.filehelper.anyfhelper

Various helpers about files

source on GitHub

Functions

function

truncated documentation

change_file_status

Changes the status of all files inside a folder.

read_content_ufs

Reads the content of a source, whether it is a url, a file, a stream or a string (in that case, it returns the string …

Documentation

Various helpers about files

source on GitHub

pyquickhelper.filehelper.anyfhelper.change_file_status(folder, status=128, strict=False, include_folder=True)[source][source]

Changes the status of all files inside a folder.

Parameters
  • folder – folder or file

  • status – new status

  • strict – False, use |=, True, use =

  • include_folder – change the status of the folders as well

Returns

list of modified files

By default, status is stat.S_IWRITE. If folder is a file, the function changes the status of this file, otherwise, it will change the status of every file the folder contains.

source on GitHub

pyquickhelper.filehelper.anyfhelper.read_content_ufs(file_url_stream, encoding='utf8', asbytes=False, add_source=False)[source][source]

Reads the content of a source, whether it is a url, a file, a stream or a string (in that case, it returns the string itself), it assumes the content type is text.

Parameters
  • file_url_stream – file or url or stream or string

  • encoding – encoding

  • asbytes – return bytes instead of chars

  • add_source – also return the way the content was obtained

Returns

content of the source (str) or (content, type)

Type can be:

  • rb: binary file

  • r: text file

  • u: url

  • ub: binary content from url

  • s: string

  • b: binary string

  • S: StringIO

  • SB: BytesIO

  • SBb: BytesIO, return bytes

The function can return bytes.

source on GitHub