Method | @@ -88,7 +114,7 @@ import filesystem as fs OS_SEPARATOR
- prints the OS separator
+ Prints the OS separator
'/' for macOS and Linux '\\' for Windows |
@@ -231,11 +257,22 @@ import filesystem as fs
---|
Method | +Description | +
---|---|
+ compression.tarfile.create_tar(fullpath_files, destination) + | ++ The function compresses files or directories into a TAR file. + Returns a message indicating whether a single file/directory or a list of files/directories was compressed. + | +
+ compression.tarfile.extract(tar_filename, destination, extraction_list=[]) + | ++ Extract files from a tar archive. It can extract all files or a specified list of files from the archive. + Returns True if the extraction is successful, [FileSystem Pro]: File Not Found if the tar file is not found, False if a specified item in extraction_list is not found and Error Message if any other error occurs during extraction. + | +
+ compression.tarfile.read_tar_archive(tar_filename) + | ++ Reads the contents of a TAR archive file and returns a list of the names of the files contained within it. + | +
+ compression.zipfile.create_zip(fullpath_files, destination) + | ++ The function compresses files or directories into a ZIP file. + Returns a message indicating whether a single file/directory or a list of files/directories was compressed. + | +
+ compression.zipfile.extract(zip_path, destination, extraction_list=None) + | ++ Reads the contents of a ZIP file and extracts files based on the provided parameters. + | +
+ compression.zipfile.read_zip_archive(zip_filename, show_compression_system_files=True) + | ++ Reads the contents of a ZIP file and returns a list of the names of the files contained within it. + | +
Constants | @@ -306,9 +588,15 @@ This library is a key addition to FileSystemPro as a third-party library, enhanc
---|
Method | +Description | +
---|---|
+ directory.combine(*args, paths=[]) + | ++ Combines a list of paths or arguments into a single path. If the first argument or the first element in the paths list is not an absolute path, it raises a ValueError. + | +
Method | -Description | +Method | +Description |
---|---|---|---|
directory.combine(*args, paths=[]) | ++ directory.combine(*args, paths=[]) + | Combines a list of paths or arguments into a single path. If the first argument or the first element in the paths list is not an absolute path, it raises a ValueError. | |
+ directory.create(path, create_subdirs = True) + | ++ Creates a directory at the specified path. If `create_subdirs` is True, all intermediate-level + directories needed to contain the leaf directory will be created. After the directory is created, + it returns the details of the created directory. + | +||
+ directory.delete(path, recursive=False) + | ++ Deletes a directory at the specified path. If `recursive` is True, the directory and all its contents will be removed. + | +||
+ directory.exists(path) + | ++ Checks if a directory exists at the specified path. + | +||
+ directory.get_directories(path, fullpath=True) + | ++ Create a list of directories within a specified path and returns either their full paths or just their names based on the fullpath parameter. Defaults to True. + | +||
+ directory.get_name(path) + | ++ Retrieves the name of the directory of the specified path. + If the path has an extension, it is assumed to be a file, and the parent directory name is returned. + If the path does not have an extension, it is assumed to be a directory, + and the directory name is returned. + | +||
directory.create(path, create_subdirs = True) | - Creates a directory at the specified path. If `create_subdirs` is True, all intermediate-level - directories needed to contain the leaf directory will be created. After the directory is created, - it returns the details of the created directory. + directory.get_parent(path) + | ++ Retrieves the parent directory from the specified path. + | +|
+ directory.get_parent_name(path) + | ++ Retrieves the parent directory name from the specified path. | ||
directory.delete(path, recursive=False) | +|||
- Deletes a directory at the specified path. If `recursive` is True, the directory and all its contents will be removed. - | - -|||
directory.exists(path) | + directory.get_size(directory_path) +- Checks if a directory exists at the specified path. - | + Calculates the total size of all files in the specified directory. The size is returned in bytes, KB, MB, GB, or TB, depending on the total size. + +||
directory.get_directories(path, fullpath=False) | - Retrieves a list of directories within the specified path. - | - -||
directory.get_name(path) | + directory.join(path1='', path2='', path3='', path4='', paths=[]) +- Retrieves the name of the directory of the specified path. - If the path has an extension, it is assumed to be a file, and the parent directory name is returned. - If the path does not have an extension, it is assumed to be a directory, - and the directory name is returned. - | + Joins multiple directory paths into a single path. The function ensures that each directory path ends with a separator before joining. If a directory path does not end with a separator, one is added. + +||
directory.get_parent_name(path) | - Retrieves the parent directory name from the specified path. - | - -||
directory.get_parent(path) | + directory.move(source, destination, move_root=True) +- Retrieves the parent directory from the specified path. - | - + The move function is designed to move files or directories from a source location to a destination. + It provides flexibility by allowing you to specify whether intermediate-level subdirectories should be created during the move operation. + +||
directory.join(path1='', path2='', path3='', path4='', paths=[]) | - Joins multiple directory paths into a single path. The function ensures that each directory path ends with a separator before joining. If a directory path does not end with a separator, one is added. - | - -||
directory.rename(old_path, new_path) | + directory.rename(old_path, new_path) +- Renames a directory from the old directory path to the new directory path. If the old directory path does not exist or is not a directory, the function returns False. - | + Renames a directory from the old directory path to the new directory path. If the old directory path does not exist or is not a directory, the function returns False. +
Method | @@ -615,10 +1169,9 @@ file creation, deletion, enumeration, and file splitting and reassembling.||
---|---|---|
file.create(file, data, encoding="utf-8") | +file.create(file, data, overwrite=False, encoding="utf-8") | - Creates a file at the specified path and writes data into it. If the file already exists, - its contents are overwritten. The function then returns the details of the created file. + Creates a file at the specified path and writes data into it. If the file already exists, its contents can be either appended to or overwritten based on the overwrite parameter. The function then returns the details of the created file |
file.find_duplicates(path) | ++ Finds duplicate files in a given directory and its subdirectories. + A file is considered a duplicate if it has the same checksum as another file. + | +|
file.get_extension(file_path, lower=True) | @@ -660,12 +1221,20 @@ file creation, deletion, enumeration, and file splitting and reassembling. | |
file.get_files(path, fullpath=False, extension=None) | +file.get_files(path, fullpath=True, extension=None) | Retrieves a list of files from the specified directory. Optionally, it can return the full path of each file and filter files by their extension. |
file.get_size(file_path) | ++ Calculates the size of a file at the specified path. + The size is returned in bytes, KB, MB, GB, or TB, depending on the size. + | +|
file.move(source, destination, new_filename=None, replace_existing=False) | @@ -697,12 +1266,16 @@ file creation, deletion, enumeration, and file splitting and reassembling. Splits a large file into smaller chunks. The function reads the file in chunks of a specified size and writes each chunk to a new file. The new files are named by appending `.fsp` and an index number to the original filename. |
Method | -Description | -Status | -||
---|---|---|---|---|
wrapper.combine(*args, paths=[]) | -
- This function is designed to combine file or directory paths. It takes any number of arguments *args and an optional parameter paths which is a list of paths. The function returns a combined path based on the inputs.
- If the paths list is provided, the function uses it to combine paths. It starts with the first path in the list and checks if it’s an absolute path. If it’s not, it raises a ValueError with a detailed error message. Then, it iterates over the rest of the paths in the list. If a path is absolute, it replaces the current result with this path. If a path is relative, it joins this path to the current result. Finally, it returns the combined path.
- If the paths list is not provided or is empty, the function uses the arguments passed *args. It starts with the first argument and checks if it’s an absolute path. If it’s not, it raises a ValueError with a detailed error message. Then, it iterates over the rest of the arguments. If an argument is an absolute path, it replaces the current result with this path. If an argument is a relative path and not an empty string, it adds this path to the current result. If the current result doesn’t end with a separator (os.sep), it adds one before adding the path. Finally, it returns the combined path.
- Please note: This function does not check if the paths exist or are valid, it only combines them based on the rules described. It’s up to the caller to ensure that the paths are valid and exist if necessary. - This method is intended to concatenate individual strings into a single string that represents a file path. However, if an argument other than the first contains a rooted path, any previous path components are ignored, and the returned string begins with that rooted path component. As an alternative to the combine method, consider using the join method. - |
- - Under support. Consider using directory.combine(*args, paths=[]) - | -||
- wrapper.create_directory(path, create_subdirs=True) - | -
- This function is used to create a directory at the specified path. If create_subdirs is True, the function creates all intermediate-level directories needed to contain the leaf directory. If create_subdirs is False, the function will raise an error if the directory already exists or if any intermediate-level directories in the path do not exist.
- Default is True - If the directories already exist, it does nothing. - |
- - Under support. Consider using directory.create(path, create_subdirs = True) - | -||
- wrapper.create_file(file_name, path, text, encoding="utf-8-sig") - | -
- The function attempts to open a file at the specified path with the given file_name (with extension), in write mode with the specified encoding. It then writes the provided text into the file.
- Finally, it calls Wrapper get_object with the full path to the newly created file and returns the resulting dictionary. - |
- - Under support. Consider using file.create(file, data, encoding="utf-8-sig") - | -||
- wrapper.delete(path, recursive=False) - | -- This function is designed to delete a directory at a given path. - If recursive is set to True, the function will delete the directory and all its contents. If it’s False, the function will only delete the directory if it’s empty. Default is False. - | -- Under support. Consider using directory.delete(path, recursive=False) - | -||
- wrapper.find_duplicates(path) - | -- Finds duplicate files in a given directory and its subdirectories. A file is considered a duplicate if it has the same checksum as another file. - | -- Supported - | -||
- wrapper.enumerate_files(path) - | -- This function performs a depth-first traversal of the directory tree at the given path (after expanding any user home directory symbols). It returns a list of dictionaries containing the attributes of each file and directory in the tree. - | -- Under support. Consider using file.enumerate_files(path) - | -
- wrapper.get_files(path) - | -- This function takes a path as input (which can include wildcards), expands any user home directory symbols (~), and returns a list of dictionaries containing the attributes of each file or directory that matches the path. - | -- Under support. Consider using file.get_files(path) - | +Method | +Description |
---|---|---|---|---|
wrapper.get_object(path) @@ -874,23 +1384,6 @@ Wrapper is a comprehensive toolkit that provides a set of utility functions spec | This function takes a file or directory path as input and returns a dictionary containing various attributes of the file or directory. These attributes include the time of last modification, creation time, last access time, name, size, absolute path, parent directory, whether it's a directory or file or link, whether it exists, and its extension (if it's a file). | -- Supported - | -||
- wrapper.get_size(file_path) - | -- Calculates the size of the file or directory at the specified path. If the path is a directory, - it calculates the total size of all files in the directory. The size is returned in bytes, KB, - MB, GB, or TB, depending on the size. - | -- Supported - | ||
Checks if the given file path has an extension. This function can return True or False based on the string, even if the file or directory does not exist. | -- Supported - | -|||
- wrapper.join(path1='', path2='', path3='', path4='', paths=[]) - | -
- This function is designed to concatenate directory paths. It takes four optional string parameters path1, path2, path3, path4 and an optional list of paths paths. The function returns a single string that represents the concatenated path.
- For each of the parameters path1, path2, path3 and path4, the function checks if the path ends with a separator. If it doesn’t, and the path is not an empty string, it adds a separator to the end of the path. - If the paths list is provided and is not empty, the function iterates over each item in the list. For each item, it checks if the item ends with a separator. If it doesn’t, it adds a separator to the end of the item. - Finally, the function returns the concatenated path. - Please note: This function does not check if the paths exist or are valid, it only combines them based on the rules described. It’s up to the caller to ensure that the paths are valid and exist if necessary. - Unlike the combine method, the join method does not attempt to root the returned path. (That is, if path2 or path3 or path4 is an absolute path, the join method does not discard the previous paths as the combine method does). - |
- - Under support. Consider using directory.join(path1='', path2='', path3='', path4='', paths=[]) - | -||
- wrapper.list_directories(path) - | -- This function returns a list of all the directories in a given directory. - | -- Under support. Consider using directory.get_directories(path) - | -||
- wrapper.list_files(path) - | -- This function returns a list of all the files in a given directory. - | -- Under support. Consider using file.get_files(path) - | -||
- wrapper.make_zip(source, destination) - | -- This function is used to create a zip archive of a given source directory and move it to a specified destination. - | -- Supported - | ||
- wrapper.read_zip_file_contents(zip_filename) - | -- Reads the contents of a ZIP file and returns a list of the names of the files contained within it. - | -- New implementation - | -
Method | @@ -1102,11 +1525,15 @@ Watcher serves as a monitoring system for the file system. It keeps track of any
---|