import os
import argparse
def print_file_or_dir(filename, is_dir):
print(filename + ("/" if is_dir else ""))
def traverse_directory(directory, callback):
if os.path.isdir(directory):
filenames = sorted(os.listdir(directory))
for filename in filenames:
full_path = os.path.join(directory, filename)
callback(filename, os.path.isdir(full_path))
else:
print(f"{directory} is not a valid directory.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Print the files and directories in a directory.')
parser.add_argument('dir', type=str, help='The directory to list files and directories from')
args = parser.parse_args()
traverse_directory(args.dir, print_file_or_dir)