Finished code for part 1. Tested a few cases with ls and echo. Extreme case not tested.