Parse command-line arguments and execute the file organizer.
()
| 94 | |
| 95 | |
| 96 | def main() -> None: |
| 97 | """Parse command-line arguments and execute the file organizer.""" |
| 98 | parser = argparse.ArgumentParser( |
| 99 | description="Organize files in a directory into categorized subfolders." |
| 100 | ) |
| 101 | parser.add_argument("--path", required=True, help="Directory path to organize.") |
| 102 | parser.add_argument( |
| 103 | "--interval", |
| 104 | type=int, |
| 105 | default=0, |
| 106 | help="Interval (in minutes) to repeat automatically (0 = run once).", |
| 107 | ) |
| 108 | args = parser.parse_args() |
| 109 | |
| 110 | if not os.path.exists(args.path): |
| 111 | print(f"Path not found: {args.path}") |
| 112 | return |
| 113 | |
| 114 | print(f"Watching directory: {args.path}") |
| 115 | print("Organizer started. Press Ctrl+C to stop.\n") |
| 116 | |
| 117 | try: |
| 118 | while True: |
| 119 | organize_files(args.path) |
| 120 | if args.interval == 0: |
| 121 | break |
| 122 | print(f"Waiting {args.interval} minutes before next run...\n") |
| 123 | time.sleep(args.interval * 60) |
| 124 | except KeyboardInterrupt: |
| 125 | print("\nOrganizer stopped by user.") |
| 126 | |
| 127 | |
| 128 | if __name__ == "__main__": |
no test coverage detected