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 on coursehero.com
# 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
C++
We want to build an address book that is capable of storing name, address & phone number ofa person. Address book provides functionality in the form of a menu. The feature list includes:
• Add – to add a new person record• Delete – to delete an existing person record by name• Search – to search a person record by name
.. Sort - to sort the file after adding a new person record.
· Exit – to exit from application
arrow_forward
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
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
Python question: I have a .py file in another folder in the same directory how do I import that file into another .py file?
For example, my directory folder is called "School_Work"
I have 2 folders:
Helper_Functions
Main_Driver
In my Helper_Functions folder I have the file called helper_functions.py and in my main driver I have a file called main.py. I want to import helper_functions.py into main.py. How do I do that?
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
Task1:
Create a directory say, "Linux user" and it contains three files (e.g.; A, B, C). Change the directory
permission first for "user", “group", “others", “all" then change the permission of files residing
in the same folder/directory.
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
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
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 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
POWERSHELL TASK
Try to multiply two numbers stored into a file and the file name should be a command-line argument.
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
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
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
IN PYTHON - please help with lines beginning with ###TODO
import csvimport random as randimport sys
# define functions def load_csv_data(filename): """ load the data from csv file returns a tuple containing two lists: col_names: first row of csv file (list of strings) row_data: all other rows of csv file (list of list of strings) if error is encountered reading filename, returns -1 """ try: data = [] ### TODO - load the data from csv file ### use csv.reader to append rows of filename to data except: print("Error loading data.") return -1
# if successful, return tuple of column names and row data col_names = data[0] row_data = data[1:] return (col_names, row_data)
def display_menu(): ### TODO - print the main menu print("Main Menu") print("1 - Get Clean Sample") print("2 - Calculate Total Profit in Sample") print("Q - Quit")
def get_valid_menu_option(): ### TODO - get valid menu…
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
File Attributes
5. File attributes
(a) File name: file name is a very important file attribute When a file changes name, it seems to change its
identity (just like when you change your name)
The oldest file naming we may remember is the 8 +3 convention in DOS (in DOS, all file names can NOT be
bigger than 8 characters, special characters like spaces were not allowed etc.). So a file like C:\\Program
Files\\Adobe\\Photoshop can cause problems in DOS, and it has to be represented in different ways using strange
character like~ (tilde).
Elaborate on your understanding of file names or file naming in different operating systems (Windows, Mac,
Linux etc.). For example, some OS like NTFS may allow longer file name, allow space, and even allow non
English like characters such as Chinese file names. Is there a maximum length of file names (can you have a file
name of 1,000 characters long?)
(b) File creation date and modification date. File can be created and modified using different ways of…
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
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
In a contiguous allocation, if the file has n blocks long and starts at location b, the starting and last blocks being occupied by the file is ___ respectively.
a. b and b + n - 1
b. n and b + n + 2
c. b and b + n
d. n and n + b -1
arrow_forward
* Question Completion Status:
A Moving to another question will save this response.
Question 1
Run-time binding is useful for saving on memory because :
It is static linking
Only load modules when they're needed.
Ob.
Don't allow several processes to share one copy of a module.
modules cannot be loaded
d.
A Moving to another question will save this response.
O
DELL
arrow_forward
If a file contains an index directory that allows for random access, what does it mean?
arrow_forward
A file is preferable to an array of structures because
A.
file lives even after the program that created it terminates
B.
memory space will not be wasted
C.
there are many system tools to manipulate files
D.
All of the abone
arrow_forward
C++
You must create a header file for each task with implementation as the execute task.
Input file A contains numeric values and the Output File A is sorted.
Algorithm:
a ← read Value from file (A);
while not End Of File (A) {
b ← read Value from file (A);
If a> b {
return false;
}
a ← b;
}
return true;
arrow_forward
Instructions
Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed.
Be sure to include error recovery in the program. If the user enters a filename that does not exist they should be prompted to enter a filename that does exist.
An example of the program input and output is shown below:
/root/sandbox 1 List the current directory 2 Move up 3 Move down 4 Number of files in the directory 5 Size of the directory in bytes 6 Search for a file name 7 View the contents of a file 8 Quit the program Enter a number: 7 Files in /root/sandbox: filesys.py example.txt Enter a file name from these names: example.txt THIS IS CONTENT OF AN EXAMPLE FILE. /root/sandbox 1 List the current directory 2 Move up 3 Move down 4 Number of files in the directory 5 Size of the directory in bytes 6…
arrow_forward
C++
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.
Take a screenshot of a sample output and upload the picture as part of your assignment submission.
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…
arrow_forward
Use EMACS to correct the script below:
################################################ Favorite Food# Repair this script# Enters Fish & Chips# Bring about a file with the food name and the calculation in the file: foods# Date: 03/31/2022# Note: this script has errors... please repair them!################################################## ask the user what their favorite food isecho -n "What do I like to eat? "# Read in the estimateread estimate## Set calculation to zerocalculation=999Utilize a while loop to read in the food name until "Fish & Chips" is entered#while test $foodname != "Fish & Chips" ; do## add one to calculation let calculation=calculation+1## write out the food to a file called foods echo "$estimate:$calculation" >> echo $estimate "Nope, try again! "; read estimatedone
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Related Questions
- C++ We want to build an address book that is capable of storing name, address & phone number ofa person. Address book provides functionality in the form of a menu. The feature list includes: • Add – to add a new person record• Delete – to delete an existing person record by name• Search – to search a person record by name .. Sort - to sort the file after adding a new person record. · Exit – to exit from applicationarrow_forwardWith 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_forwardWrite 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_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 itarrow_forwardPython question: I have a .py file in another folder in the same directory how do I import that file into another .py file? For example, my directory folder is called "School_Work" I have 2 folders: Helper_Functions Main_Driver In my Helper_Functions folder I have the file called helper_functions.py and in my main driver I have a file called main.py. I want to import helper_functions.py into main.py. How do I do that?arrow_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
- Task1: Create a directory say, "Linux user" and it contains three files (e.g.; A, B, C). Change the directory permission first for "user", “group", “others", “all" then change the permission of files residing in the same folder/directory.arrow_forwardThe 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_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
- 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 & 89arrow_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_forwardPOWERSHELL TASK Try to multiply two numbers stored into a file and the file name should be a command-line argument.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning