Advertisement
juanmartinvk

Python Operating System: Week 2 Practice Quiz ex 2

Jan 13th, 2020
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import os
  2.  
  3. def new_directory(directory, filename):
  4.   # Before creating a new directory, check to see if it already exists
  5.   if not os.path.exists(directory):
  6.     os.mkdir(directory)
  7.   os.chdir(directory)
  8.   # Create the new file inside of the new directory
  9.   file = open(filename, "x")
  10.   file.close()
  11.   # Return the list of files in the new directory
  12.   return os.listdir()
  13.  
  14. print(new_directory("PythonPrograms", "script.py"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement