diff --git a/README.md b/README.md index 132ed42..95de4d6 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ scanner -i .\tests -f "test.pdf" # Convert all jpg, jpeg, png, webp files in folder to one pdf file scanner -i .\tests -f "image" +# Convert all image files in folder in the order of file names +scanner -i .\tests -f "image" -s "name" + # Convert all png files in folder to pdf with 100% quality to one pdf file scanner -i .\tests -f "png" -q 100 @@ -101,6 +104,9 @@ These are the command-line arguments accepted: - `-r, --recurse` : Allows scripts to find all matching files including subdirectories. Accepted values are "yes" or "no". The default value is "yes". - Example: `-r yes` or `--recurse no` +- `-s, --sort_by` : Allows scripts to sort the files based on name, creation time or modified time. Accepted values are "name", "ctime", "mtime", "none". The default value is "name". If "none" is selected, then the default order of files returned by the OS is used for document conversion. + - Example: `-s name` or `--sort_by none` + ❗❗ **Note:** ❗❗ diff --git a/scanner/scanner.py b/scanner/scanner.py index e4d773a..99ae3b3 100644 --- a/scanner/scanner.py +++ b/scanner/scanner.py @@ -141,8 +141,10 @@ def get_blackandwhite(args): return _is_true(args.black_and_white) def get_sort_key(args): + """Return the key with which files should be sorted and then coverted""" sort_by = args.sort_by.lower().strip() - return {"name": os.path.abspath, "ctime": os.path.getctime, "mtime": os.path.getmtime}.get(sort_by) + key_map = {"name": os.path.abspath, "ctime": os.path.getctime, "mtime": os.path.getmtime} + return key_map.get(sort_by) def get_file_type(args): """Get file type and supported documents based on input arguments""" @@ -433,7 +435,7 @@ def find_matching_files(input_folder, file_type_list, recurse=False, sort_key=No print_color(f"Permission denied: {input_folder}", "red") except Exception as err: print_color(f"Error when searching for files: {err}", "red") - + # Sort the list of files if sorting is requested by user if sort_key: files_list.sort(key=sort_key)