IO module¶
File I/O related operations, such as list files, import/export or remove files/folder.
-
IO.
CompressFiles
(Paths, CompressedFilePath, Format='zip')[source]¶ Compress files into a (zip) file.
Parameters: - Paths (List) – Paths of the files you want to compress. These paths will be under the root of the compressed file.(You may want to use ListFiles to pass in all paths)
- CompressedFilePath (String) – Path of the compressed file you want to store.
- Format (String) – The format of the compressed file.
-
IO.
CopyFolderStructure
(SourceFolder, DestinationFolder, Root=False)[source]¶ Copy a folder structure without copying any of the files inside of it.
Parameters: - Directory (String) – Path of the source folder
- Directory – Path of the destination folder that the source folder structure will be copied
- Root (Boolean) – DestinationAsRoot. If this is True, the DestinationFolder will be ragarded as a folder of the same level of SourceFolder, otherwise SourceFolder will be copied into the DestinationFolder
-
IO.
DecompressFiles
(Paths, TargetFolder, Format='zip')[source]¶ Decompress files from a (zip) file/files.
Parameters: - Paths (List) – Paths of the files you want to decompress.
- TargetFolder (String) – Path of the decompressed files you want to store.
- Format (String) – The format of the compressed file.
-
IO.
DownloadFile
(URL, Destination='./download', ExpectedBytes=None, IsDestinationFolder=None)[source]¶ Download a file if not present, and make sure it’s the right size.
Parameters: - URL (String) – URL of the file you want to download.
- Destination (String) – Path of the file you want to store, it can be a.
- Format (String) – The format of the compressed file.
-
IO.
ExportToJson
(Path, Content)[source]¶ Export something to json file. Will automatic convert Set content into List.
Parameters: - Path (String) – Path to store the json file
- Content (Variant) – something you want to export
-
IO.
ExportToPkl
(Path, Content)[source]¶ Export something to pickle file. Will automatic convert Set content into List.
Parameters: - Path (String) – Path to store the json file
- Content (Variant) – something you want to export
-
IO.
FileExist
(FilePath)[source]¶ Given file path, determine a file exist or not.
Parameters: FilePath (String) – Path of a file or directory Return type: Boolean
-
IO.
GetFileHash
(FilePath, HashFactory=<built-in function openssl_md5>, ChunkNumBlocks=128)[source]¶ Parameters: - FilePath – Paths of the file you want to calculate file hash.
- HashFactory – Algorithm of hash calculation. By default, it’s MD5.
- ChunkNumBlocks – Number of Blocks to be read. Use 128 as default.
Returns: Hash: Hex representation of file hash
:rtype String
-
IO.
GetParentFolders
(FilePath, All=False)[source]¶ Use pathlib to get parent folder/list of parent folders of FilePath.
Parameters: FilePath (String) – Path of a file/folder Returns: ParentFolder/ParentFolders: String of its parent folder or list of string of its parent folders Return type: String or List[String]
-
IO.
ImportFromJson
(Path)[source]¶ Import something from json file.
Parameters: Path (String) – Path of the json file Returns: Content: Content in the json file Return type: Variant
-
IO.
ImportFromPkl
(Path)[source]¶ Import something from pickle file.
Parameters: Path (String) – Path of the pickle file Returns: Content: Content in the pickle file Return type: Variant
-
IO.
ListApkFiles
(ApkDirectory)[source]¶ Get the Apk file names for an ApkDirectory in a sorted order. Rerurn an empty list if ApkDirectory==””.
Parameters: ApkDirectory (String) – Path of a apk file directory Returns: ListOfApkFiles: The list of Paths of Apks under ApkDirectory Return type: List[String]
-
IO.
ListFiles
(Directory, Extension, All=False)[source]¶ Given an extension, get the file names for a Directory in a sorted order. Rerurn an empty list if Directory == “”.
Parameters: - Directory (String/List) – Path/Paths of a file directory
- Extension (String) – Extension of the files you want. Better include “.” in the Extension. Use “.” to list all files. Use “”(empty string) to list all folders.
- All (Boolean) – Whether to include all files in sub-directories
Returns: ListOfFiles: The list of Paths of the files you want under Directory
Return type: List[String]