Skip to content

Instantly share code, notes, and snippets.

@RabeyaMuna
Created May 7, 2020 02:31
Show Gist options
  • Save RabeyaMuna/0617fc8a36fc4e28d2822c097cb0cbcc to your computer and use it in GitHub Desktop.
Save RabeyaMuna/0617fc8a36fc4e28d2822c097cb0cbcc to your computer and use it in GitHub Desktop.
The new_directory function creates a new directory inside the current working directory, then creates a new empty file inside the new directory, and returns the list of files in that directory. Complete the function to create a file "script.py" in the directory "PythonPrograms".
import os
def new_directory(directory, filename):
# Before creating a new directory, check to see if it already exists
if not os.path.exists(directory):
os.mkdir(directory)
name=os.path.join(directory, filename)
file=open(name,'w')
file.close()
return os.listdir(directory)
# Create the new file inside of the new directory
# Return the list of files in the new directory
print(new_directory("PythonPrograms", "script.py"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment