Lab3 Task 2 Trent King
.docx
keyboard_arrow_up
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
Related Questions
With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhereon the disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointerto the next block. Refer to the illustration below.
Need help to fill in the codes in void main() ---
#include<stdio.h>#include<stdlib.h>#define TOTAL_DISK_BLOCKS 32#define TOTAL_DISK_INODES 8int blockStatus[TOTAL_DISK_BLOCKS]; // free = 0int blockList[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES]; // list of blocks of a filestruct file_table {char fileName[20];int fileSize;struct block *sb;};struct file_table fileTable[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES];struct block {int blockNumber;struct block *next;};int AllocateBlocks(int Size) {---}void main(){int i = 0, j = 0, numFiles = 0, nextBlock= 0, ret = 1;char s[20]; struct block *temp;---for(i = 0; i < numFiles; i++) {---ret = AllocateBlocks(fileTable[i].fileSize);---}---//Seed the pseudo-random number…
arrow_forward
Computer Science
all scripts and commands are based in Bash shell CLI
arrow_forward
Write operations that can be performed on a directory.
arrow_forward
Write the comdlet to create the following directory structure: mid term and MCQ(Subdirectory) are directories and file.txt and short.txt are files
Mid Term
MCQ
file.txt
short.txt
Short-Answer
true.txt
arrow_forward
10. The write permission for a directory determines that
a) we can write to a directory file
b) we can read the directory file
c) we can execute the directory file
d) we can add or remove files to it
arrow_forward
Unix assignment
Purpose: The purpose of this assignment is to use various concepts of
the C Shell.
0. Change your default login shell to the C Shell.
1. Create a .cshrc file in your home directory that will do
the following:
* Create the alias (lsall) that will do all of the following:
display the date, and a recursive long list of all files
in a directory.
* Create the alias (whoson) that will display the date and a sorted
list of users logged in.
* Declare the LOCAL variable that controls the size of your history
list to the value 200.
* Declare the shell variable that will cause the C Shell to send
a message to your terminal whenever one of your background
commands complete.
2. Create a .login file in your home directory to do the following.
* Declare the GLOBAL Terminal Type variable to the
value vt100. Display the value of the variable.
Logout and log back in to make sure your .cshrc and .login files
are automatically executed.
Create a lab8.scr…
arrow_forward
The minimum permissions you need to read the contents of the directory dir1 is:
x on dir1
rwx on dir1
Or on dir1
rx on dir1
arrow_forward
Exercise
Exercise 3: Add a new command call 'I' which will
perform exact same as 'Is -a'.
• Exercise 4: Create a function call sortFile, which will
sort all filenames of current directory.
F5
30
tv
F6
8
JA &
89
arrow_forward
The Directory class has a list of names in it. You should use dynamic memory to create anarray upon instantiation. You should create a copy constructor for the directory class and anassignment operator (i.e. operator=()). You should create a function called fillDirectory whichaccepts a size for the directory and the names for it both of which should be given by the user.In main, create directory1 and fill it with information. Use the assignment operator=() to setdirectory2 equal to directory1.
This is in c++
arrow_forward
Programming language: python3
Write a function that creates a new folder called “hw3-folder” inside the current directory (the one where your code is running).
arrow_forward
the state and variable display must be:Unsorted Partition Reference Index: 0, Traversing Index: 7, Current Traversing Index Value: mango, Next Index Value: plum, Swapping Condition: FalseCurrent Array: ['apple', 'avocado', 'orange', 'banana', 'strawberry', 'pineapple', 'plum', 'mango']
The input:["apple", "avocado", "orange", "banana", "strawberry", "pineapple", "plum", "mango"]Note:The sorted partition is on the left side. Then, the order is increasing based on the number of vowels of a string.the output must be like this:['plum', 'apple', 'strawberry', 'mango', 'orange', 'banana', 'avocado', 'pineapple']
-------
What is the 3rd item of the unsorted partition when there are already 2 items in sorted partition and after the 3rd traversal?
arrow_forward
C++
Assignment Setup
Part 1: Working With Process IDs
Modify the getProcessID() function in the file named Processes.cpp
The function must find and store the process's own process id
The function must return the process id to the calling program. Note that the function currently returns a default value of -1.Hint: search for “process id” in the “System Calls” section of the Linux manual.
Part 2: Working With Multiple Processes
Modify the createNewProcess() function in the file named Processes.cpp as follows:
The child process must print the message I am a child process!
The child process must then return a string with the message I am bored of my parent, switching programs now
The parent process must print the message I just became a parent!
The parent process must then wait until the child process terminates, at which point it must return a string with the message My child process just terminated! and then terminate itself. Hint: search for “wait for process” in…
arrow_forward
If wrong answer this time will downvote it
Create a class with a static main that tests the ability to resolve and print a Path:
• Create an instance of a FileSystem class.
• Resolve an instance of a Path interface from a directory path and filename.
• Print the constructed Path with System.out.println() method.
2. Create a class with a static main that tests the ability to resolve and print a Path:
• Create an array of Path class.
• Instantiate instances of Path with absolute and relative paths.
• Print the constructed elements of the array of Path class with System.out.println() method.
3. Create a class to test serialisation class that implements serializable, it should implement the following:
• A static void method that serialises an object.
• A static void method that deserializes an object.
• A static main method that tests the two by moving an object from one to the other
arrow_forward
javascript
arrow_forward
Add comments for assignment p05Thanks! Run it with C, Linux
arrow_forward
POWERSHELL TASK
Try to multiply two numbers stored into a file and the file name should be a command-line argument.
arrow_forward
79.
The type of allocation in which blocks of file are allocated to consecutive blocks of disks is classified as
a.
indexed allocation
b.
header allocation
c.
contiguous allocation
d.
linked allocation
arrow_forward
Exercise 2 - Create a directory structure
Write a batch program called EX2.BAT that creates the following directory structure on drive E.
D:\
ACCOUNT1
rESOUNT2
Letters
Email
Java
Аpps
Check either in Explorer or at the prompt that the directory structure shown above has been created.
Add comments to all your batch files using Rem command at start of the line. The comments should
indicate the following:
Program purpose
Author
Date written
13 |Page
Run the batch file EX2.BAT. Are you now in a different folder to the one you were in before
you ran the batch file. You should not move directory as a result of running a batch file unless
that is part of the batch file.
arrow_forward
Linear list directory structures have the disadvantage that you must search an entire linked list to ensure that a new file doesn't match a name already in the directory.
Question 2 options:
True
False
arrow_forward
USE C SHARP LANGUAGE AND CODE MUST GET COMPILED IN VISUAL STUDIO.
QUESTION PROVIDED IN ATTACH IMAGE.
arrow_forward
POWERSHELL TASK
Try to swap two strings/names in a file and the file name should be a command-line argument.
arrow_forward
A movie file has the following record structure:name ofthe movie producer director type productioncostAssume that the name of the movie is the primary key of the file. Thefield type refers to the type of the movie, for example, drama, sci-fi, horror, crimethriller, comedy and so forth. Input a sample set of records of your choice into themovie file.i) Implement a primary index-based ISAM file organization.ii) Implement secondary indexes on director, type and productioncost.
arrow_forward
If a file contains an index directory that allows for random access, what does it mean?
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Related Questions
- With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhereon the disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointerto the next block. Refer to the illustration below. Need help to fill in the codes in void main() --- #include<stdio.h>#include<stdlib.h>#define TOTAL_DISK_BLOCKS 32#define TOTAL_DISK_INODES 8int blockStatus[TOTAL_DISK_BLOCKS]; // free = 0int blockList[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES]; // list of blocks of a filestruct file_table {char fileName[20];int fileSize;struct block *sb;};struct file_table fileTable[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES];struct block {int blockNumber;struct block *next;};int AllocateBlocks(int Size) {---}void main(){int i = 0, j = 0, numFiles = 0, nextBlock= 0, ret = 1;char s[20]; struct block *temp;---for(i = 0; i < numFiles; i++) {---ret = AllocateBlocks(fileTable[i].fileSize);---}---//Seed the pseudo-random number…arrow_forwardComputer Science all scripts and commands are based in Bash shell CLIarrow_forwardWrite operations that can be performed on a directory.arrow_forward
- Write the comdlet to create the following directory structure: mid term and MCQ(Subdirectory) are directories and file.txt and short.txt are files Mid Term MCQ file.txt short.txt Short-Answer true.txtarrow_forward10. The write permission for a directory determines that a) we can write to a directory file b) we can read the directory file c) we can execute the directory file d) we can add or remove files to itarrow_forwardUnix assignment Purpose: The purpose of this assignment is to use various concepts of the C Shell. 0. Change your default login shell to the C Shell. 1. Create a .cshrc file in your home directory that will do the following: * Create the alias (lsall) that will do all of the following: display the date, and a recursive long list of all files in a directory. * Create the alias (whoson) that will display the date and a sorted list of users logged in. * Declare the LOCAL variable that controls the size of your history list to the value 200. * Declare the shell variable that will cause the C Shell to send a message to your terminal whenever one of your background commands complete. 2. Create a .login file in your home directory to do the following. * Declare the GLOBAL Terminal Type variable to the value vt100. Display the value of the variable. Logout and log back in to make sure your .cshrc and .login files are automatically executed. Create a lab8.scr…arrow_forward
- The minimum permissions you need to read the contents of the directory dir1 is: x on dir1 rwx on dir1 Or on dir1 rx on dir1arrow_forwardExercise Exercise 3: Add a new command call 'I' which will perform exact same as 'Is -a'. • Exercise 4: Create a function call sortFile, which will sort all filenames of current directory. F5 30 tv F6 8 JA & 89arrow_forwardThe Directory class has a list of names in it. You should use dynamic memory to create anarray upon instantiation. You should create a copy constructor for the directory class and anassignment operator (i.e. operator=()). You should create a function called fillDirectory whichaccepts a size for the directory and the names for it both of which should be given by the user.In main, create directory1 and fill it with information. Use the assignment operator=() to setdirectory2 equal to directory1. This is in c++arrow_forward
- Programming language: python3 Write a function that creates a new folder called “hw3-folder” inside the current directory (the one where your code is running).arrow_forwardthe state and variable display must be:Unsorted Partition Reference Index: 0, Traversing Index: 7, Current Traversing Index Value: mango, Next Index Value: plum, Swapping Condition: FalseCurrent Array: ['apple', 'avocado', 'orange', 'banana', 'strawberry', 'pineapple', 'plum', 'mango'] The input:["apple", "avocado", "orange", "banana", "strawberry", "pineapple", "plum", "mango"]Note:The sorted partition is on the left side. Then, the order is increasing based on the number of vowels of a string.the output must be like this:['plum', 'apple', 'strawberry', 'mango', 'orange', 'banana', 'avocado', 'pineapple'] ------- What is the 3rd item of the unsorted partition when there are already 2 items in sorted partition and after the 3rd traversal?arrow_forwardC++ Assignment Setup Part 1: Working With Process IDs Modify the getProcessID() function in the file named Processes.cpp The function must find and store the process's own process id The function must return the process id to the calling program. Note that the function currently returns a default value of -1.Hint: search for “process id” in the “System Calls” section of the Linux manual. Part 2: Working With Multiple Processes Modify the createNewProcess() function in the file named Processes.cpp as follows: The child process must print the message I am a child process! The child process must then return a string with the message I am bored of my parent, switching programs now The parent process must print the message I just became a parent! The parent process must then wait until the child process terminates, at which point it must return a string with the message My child process just terminated! and then terminate itself. Hint: search for “wait for process” in…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage