#!/usr/bin/env python3
import sys
import os


# Simulate the behavior of the ls program

# Allow the user to specify a directory to list the contents of
if __name__ == '__main__':
    path = '.'
    # Handle arguments
    if len(sys.argv) > 1:
        # The path should be the only argument not starting with a -
        for a in sys.argv[1:]:
            if not a.startswith('-'):
                path = a
                # If the directory does not exist quit
                if not os.path.isdir(path):
                    print('Directory does not exist.')
                    exit()
                # Break since we should have found the path
                break

    # use list comprehension to ignore files begining with .
    files = [f for f in os.listdir(path)]

    # Sort our files in ascending order
    files.sort()

    # Decide on print -l behavior
    # print(' '.join(files))
    # We have string.startswith and .endswith methods
    [print(f) for f in files if not f.startswith('.')]