-
-
Save hwpplayer1/25e24bab021bedc83472b0e6fff967ac to your computer and use it in GitHub Desktop.
list.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def list_files(path): | |
| try: | |
| files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))] | |
| print(f"'{path}' içindeki dosyalar:") | |
| for f in files: | |
| print(f) | |
| except Exception as e: | |
| print(f"Hata: {e}") | |
| def list_directories(path): | |
| try: | |
| dirs = [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))] | |
| print(f"'{path}' içindeki klasörler:") | |
| for d in dirs: | |
| print(d) | |
| except Exception as e: | |
| print(f"Hata: {e}") | |
| # Kullanıcıdan yol al | |
| directory_path = input("Listelemek istediğin klasör yolunu gir: ") | |
| list_files(directory_path) | |
| list_directories(directory_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment