Lab3 Task 2 Trent King

.docx

School

University of Phoenix *

*We aren’t endorsed by this school

Course

0102

Subject

Computer Science

Date

May 4, 2024

Type

docx

Pages

2

Uploaded by ProfWillpower13160

# Lab3 Task 2 Trent King # Professor Kwan import os # List of allowed file extensions ALLOWED_EXTENSIONS = ["txt", "png", "doc", "dat"] def main(): #Print the current working directory print(f"Current directory: {os.getcwd()}") #Create a directory named CITFall2023<username> username = os.getlogin() # Get the current user's login name directory_path = os.path.join(os.path.expanduser("~"), f"CITFall2023{username}") createDir(directory_path) # Use createDir from Task 1 #Print the current directory again (should be unchanged) print(f"Current directory: {os.getcwd()}") #Prompt for the number of files and their extension numOfFiles = int(input("Enter the number of files: ")) fileExtension = input("Enter the file extension: ") if fileExtension not in ALLOWED_EXTENSIONS or numOfFiles <= 0: print("Invalid extension or number of files. Please use allowed extensions and a positive number of files.") return createFiles("file", numOfFiles, fileExtension, directory_path) #Prompt for the number of subdirectories and create them
numOfSubDirs = int(input("Enter the number of subdirectories: ")) if numOfSubDirs <= 0: print("The number of subdirectories must be greater than 0.") return for i in range(numOfSubDirs): subDirName = f"SubDir{i+1}" createDir(os.path.join(directory_path, subDirName)) #Display the contents of the CITFall2023<username> directory displayContents(directory_path) #Prompt for a new extension and rename files newExtension = input("Enter a new extension for the files: ") if newExtension not in ALLOWED_EXTENSIONS: print("Invalid extension. Please use allowed extensions.") return #Assuming renameFiles function is implemented to handle extension change renameFiles(directory_path, fileExtension, newExtension) #Display the contents again displayContents(directory_path) if __name__ == "__main__": main()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help