Reputation: 15
I have two functions one is my main_menu that lets the user input a number to invoke another function. When the number 1 is selected I get the error "NameError: name 'createDirectory' is not defined". I just thought it would be as easy as calling the function createDirectory, but obviously not. Can anyone point me in the right direction please?
from os import makedirs, path
# import shutil
def main_menu():
print("PLEASE CHOOSE AN OPTION BELOW BY ENTERING THE CORRESPONDING NUMBER: \n")
print("[1]: CREATE CASE FOLDER STRUCTURE")
print("[2]: BACK CASE UP TO SERVER")
print("[3]: CLOSE PROGRAMME \n")
main_menu()
while True:
# choice = int(input("ENTER YOUR CHOICE HERE:"))
try:
choice = int(input("ENTER YOUR CHOICE HERE:"))
if choice == 1:
createDirectory(targetPath)
main_menu()
break
elif choice == 2:
# backUpCase('src', 'dst')
main_menu()
break
elif choice == 3:
break
else:
print("INVALID CHOICE!! PLEASE ENTER A NUMBER BETWEEN 1-3")
main_menu()
except ValueError:
print("INVALID CHOICE!! PLEASE ENTER A NUMBER BETWEEN 1-3")
exit()
main_menu()
def createDirectory(targetPath):
if not path.exists(targetPath):
makedirs(targetPath)
print('Created folder ' + targetPath)
else:
print('Path ' + targetPath + ' already exists, skipping...')
# MAIN #
print('''Case Folder Initialiser
v 1.1 2015/09/14
A simple Python script for creating the folder structure required for new cases as follows;
05 DF 1234 15
+--Acquisitions
¦ ---QQ1
¦ ---QQ2
¦ ---...
+--Case File
¦ ---X Ways
¦ +--EnCase
¦ ¦ +--Temp
¦ ¦ +--Index
¦ +--NetClean
+--Export
---X Ways Carving
All user inputs are not case sensitive.
''')
driveLetter = input('Enter the drive letter for your WORKING COPY disc: ').upper()
limaReference = input('Enter the Lima reference number, such as 05 DF 12345 15: ').upper()
rootPath = driveLetter + ':/' + limaReference + '/'
print('You will now enter your exhibit references, such as QQ1. Press enter at an empty prompt to stop adding further exhibits.')
exhibits = []
while True:
exhibit = input('Enter exhibit reference: ').upper()
if not exhibit:
print('You have finished adding exhibits and the folders will now be created.')
break
exhibits.append(exhibit)
for exhibit in exhibits:
# targetPath = rootPath + 'Acquisitions/' + exhibit + '/'
# targetPath2 = 'A:/' + limaReference + '/Acquisitions/' + exhibit + '/'
targetPath = rootPath + '/Acquisitions/' + exhibit + '/'
createDirectory(targetPath)
# createDirectory(targetPath2)
targetPath = rootPath + 'Case File/X Ways/'
createDirectory(targetPath)
targetPath = rootPath + 'Case File/EnCase/Temp/'
createDirectory(targetPath)
targetPath = rootPath + 'Case File/EnCase/Index/'
createDirectory(targetPath)
targetPath = rootPath + 'Case File/NetClean/'
createDirectory(targetPath)
targetPath = rootPath + 'Export/X Ways Carving/'
createDirectory(targetPath)
print('All folders created, script has terminated.')
main_menu()
Upvotes: 0
Views: 91
Reputation: 2464
You should define your createDictionary
function before the while True
loop. In your code when you call the createDictionary
function it is still not defined.
Upvotes: 3