Question: Ruby Write a program that will do the following, in order!: Under your home directory, print to the console, the name of your current directory

Ruby

Write a program that will do the following, in order!:

  1. Under your home directory, print to the console, the name of your current directory 1PT
  2. Under your home directory, create a directory called "Lab9" 1PT
  3. Change directory to "Lab9" 1PT
  4. Print to the console the name of the current directory 1PT
  5. Using a loop, create (touch) 10 files with the name of "test_.txt" where is the number from 1 to 10
  6. Using a loop, create 5 sub-directories with the name of "subdir_" where is the number from 1 to 5
  7. List all entries within the "Lab9" sub directory in the following format: Note: Do not print the "." and ".." directories Name Type ------- ------

  1. Rename all files that end with .txt to .text
  2. Repeat step 7 ( List all entries within the "Lab9" sub directory in the following format: Note: Do not print the "." and ".." directories Name Type ------- ------ )

Write the following methods and use them to solve the problems above

  • getInodeType: This method takes the name of a file/folder as a parameter returns a value indicating the inode type(File or Directory). 5PTS
  • listEntries: Displays the contents of a directory per requirement 7 above. It takes the name of the directory as parameter 5PTS
  • createFiles:Takes the directory name and number of files to create and creates the files per requirement 5 above 5PTS
  • createSubDirectories: Takes the directory name and number of subdirectories to create and creates the subdirectories per requirement 6 5PTS

renameFiles:Uses directory name, current extension of the file, and new extension of files and renames all files based on requirement

Ruby Write a program that will do the following,

tsetseal@students-cs: /CIT33 $ ruby Lab9_Solution.rb Current directory: /home/NKU/tsetseal/CIT383 Current directory: /home/NKU/tsetseal/CIT383/Lab9 Name Type test_5.txt test_8.txt test_7.txt test_4.txt subdir_3 subdir_5 subdir_1 test_3.txt test_1.txt subdir_4 subdir_2 test_10.txt test_6.txt test_9.txt test_2.txt File File File File Directory Directory Directory File File Directory Directory File File File File Name Type subdir_3 test_9.text test_10.text test_6.text test_5.text subdir_5 test_3.text subdir_1 subdir_4 test_1.text subdir_2 test_2.text test_8.text test_7.text test_4. text Directory File File File File Directory File Directory Directory File Directory File File File File tsetseal@students-cs: /CIT33 $ ruby Lab9_Solution.rb Current directory: /home/NKU/tsetseal/CIT383 Current directory: /home/NKU/tsetseal/CIT383/Lab9 Name Type test_5.txt test_8.txt test_7.txt test_4.txt subdir_3 subdir_5 subdir_1 test_3.txt test_1.txt subdir_4 subdir_2 test_10.txt test_6.txt test_9.txt test_2.txt File File File File Directory Directory Directory File File Directory Directory File File File File Name Type subdir_3 test_9.text test_10.text test_6.text test_5.text subdir_5 test_3.text subdir_1 subdir_4 test_1.text subdir_2 test_2.text test_8.text test_7.text test_4. text Directory File File File File Directory File Directory Directory File Directory File File File File

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!