filehelper: file manipulations

compression

pyquickhelper.filehelper.gzip_files (filename, file_set, encoding = None, fLOG = <function noLOG at 0x7f2832691280>)

Compresses all files from an iterator in a zip file and then in a gzip file.

pyquickhelper.filehelper.un7zip_files (zipf, where_to = None, fLOG = <function noLOG at 0x7f2832691280>, fvalid = None, remove_space = True, cmd_line = False)

Unzips files from a zip archive compress with 7z.

pyquickhelper.filehelper.ungzip_files (filename, where_to = None, fLOG = <function noLOG at 0x7f2832691280>, fvalid = None, remove_space = True, unzip = True, encoding = None)

Uncompresses files from a gzip file.

pyquickhelper.filehelper.unrar_files (zipf, where_to = None, fLOG = <function noLOG at 0x7f2832691280>, fvalid = None, remove_space = True)

Uncompresses files from a rar archive compress with 7z on Window or unrar on linux.

pyquickhelper.filehelper.unzip_files (zipf, where_to = None, fLOG = <function noLOG at 0x7f2832691280>, fvalid = None, remove_space = True, fail_if_error = True)

Unzips files from a zip archive.

pyquickhelper.filehelper.zip_files (filename, file_set, root = None, fLOG = <function noLOG at 0x7f2832691280>)

Zips all files from an iterator.

pyquickhelper.filehelper.zip7_files (filename_7z, file_set, fLOG = <function noLOG at 0x7f2832691280>, temp_folder = ‘.’)

If 7z is installed, the function uses it to compress file into 7z format. The file filename_7z must not exist.

encryption

pyquickhelper.filehelper.decrypt_stream (key, filename, out_filename = None, chunksize = 24576, algo = ‘AES’)

Decrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, algoritm AES, Fernet.

pyquickhelper.filehelper.encrypt_stream (key, filename, out_filename = None, chunksize = 262144, algo = ‘AES’)

Encrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, algoritm AES, Fernet.

internet

pyquickhelper.filehelper.get_url_content_timeout (url, timeout = 10, output = None, encoding = ‘utf8’, raise_exception = True, chunk = None, fLOG = None)

Downloads a file from internet (by default, it assumes it is text information, otherwise, encoding should be None).

sync

pyquickhelper.filehelper.explore_folder_iterfile (folder, pattern = None, neg_pattern = None, fullname = False, recursive = True, verbose = False)

Same as explore_folder but iterates on files included in a folder and its subfolders.

pyquickhelper.filehelper.synchronize_folder (p1, p2, hash_size = 1048576, repo1 = False, repo2 = False, size_different = True, no_deletion = False, filter = None, filter_copy = None, avoid_copy = False, operations = None, file_date = None, log1 = False, copy_1to2 = False, create_dest = False, fLOG = <function fLOG at 0x7f2832691310>)

Synchronizes two folders (or copy if the second is empty), it only copies more recent files. It can walk through a git repository or SVN.

pyquickhelper.filehelper.walk (top, onerror = None, followlinks = False, neg_filter = None)

Does the same as os.walk plus does not go through a sub-folder if this one is big. Folders such build or Debug or Release may not need to be dug into.

visual

pyquickhelper.filehelper.create_visual_diff_through_html (string1, string2, notebook = False, context_size = None, inline_view = False)

The function uses jsdifflib to create a visual diff. If it was not already done, the function downloads the tool using pymyinstall.

pyquickhelper.filehelper.create_visual_diff_through_html_files (file1, file2, encoding = ‘utf8’, page = None, browser = False, notebook = False, context_size = None, inline_view = False)

Calls function create_visual_diff_through_html with the content of two files.