Question

The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite...

The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite the program so that it asks the user for the location where the new directories are to be created, and then asks the user to enter, one at a time, the relative path names of the directories it should create.

Amended additional details to the above abstraction of the requirements.

  1. The application should be multiplatform adaptive. This means that it should work on an Apple, Linux, and Windows OS. A Windows OS permits the use of drive letters and backslashes. The application should be able to create folders/directories that include drive letters for the additional drives other than the C:\ Drive

  2. The name of the assignment is “Create a Directory Path from User Input”. A path may include the creation of multiple hierarchical layers of directories/folders. The program should identify a path that contains multiple layers of folders and created the appropriate folder levels.

  3. The use should be able to enter multiple path entries during a single program execution. The program should provide away for the user to either enter the number of items being entered or have a value that indicates the end of the input

  4. The Interface of the program should explain clearly to the user what to input at every data entry input point in the program

/* CreateDirectoriesDemo.java
* CSCI 112 - Spring 2014
*
* The software in this example creates a set of folders (directories).
* It is intended as an example for CSCI 112.
*
* The directory which will contain the new set of directories is identified in
* line 23 of this code as "c:\", the root directory on most Microsoft Windows
* systems. This can be changed to place the new set of directories elsewhere.
*
* last editied 2/23/2014 by C. Herbert
*/
import java.io.*;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// Establish the location of the parent for the new set of directories.
// This could be changed to user input.
String location = "c:/";

// create a String array of the directories to be created
String[] folderPaths = {
"/Spring Semester",
"/Spring Semester/ENGL 101",
"/Spring Semester/CSCI 111",
"/Spring Semester/MATH 163",
"/Spring Semester//PHYS 111",
"/Spring Semester/CSCI 111/programs",
"/Spring Semester/CSCI 111/docs"
};

// create a File class array for directories to be created
File[] newFolders = new File[folderPaths.length];

// create new directories based on the file names in the array
for (int i = 0 ; i < newFolders.length; i++)
{

// create a File object for this new directory
// based on the parent location and each new path name
newFolders[i] = new File( location + folderPaths[i] ) ;

// make the new directory
newFolders[i].mkdir();

} // end for
} // end main()
}

Homework Answers

Answer #1

package createdirectoriesdemo;

import java.io.*;

import java.util.ArrayList;

import java.util.Scanner;

public class CreateDirectoriesDemo {

public static void main(String[] args) {

// Establish the location of the parent for the new set of directories.

// This could be changed to user input.

Scanner reader = new Scanner(System.in); // Reading from System.in

System.out.println("Enter directory path: ");

String s = reader.nextLine(); // Scans the next token of the input as an int.

//once finished

String[] folderPaths = new String[7];

String location = s;

for (int i = 0; i < 7; i++) {

System.out.println("Enter relative path: ");

folderPaths[i] = reader.nextLine();

}

// create a String array of the directories to be created

reader.close();

// create a File class array for directories to be created

File[] newFolders = new File[folderPaths.length];

// create new directories based on the file names in the array

for (int i = 0 ; i < newFolders.length; i++)

{

// create a File object for this new directory

// based on the parent location and each new path name

newFolders[i] = new File( location + folderPaths[i] ) ;

// make the new directory

newFolders[i].mkdir();

} // end for

} // end main()

} // end class CreateDirectoriesDemo

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a c++ program that can take an input file with string as for example "i...
write a c++ program that can take an input file with string as for example "i saw 5 teddy bears" and in a created output file create a new string to just change a digit to a word. To " I saw five teddy bears" . output should be located in an output file thank you
The course is server management and I am using FREEBSD Create a folder off the root...
The course is server management and I am using FREEBSD Create a folder off the root that can be used for the backed-up files. You will need to use root to create this directory. Set the user and group for this directory to the account that you normally log in to. Create a cron process that will run every thirty minutes and copy the complete contents, including directories and their contents, to the backup location. The copy command should use...
C++ create a program that: in main: -opens the file provided for input (this file is...
C++ create a program that: in main: -opens the file provided for input (this file is titled 'Lab_HW10_Input.txt' and simply has 1-10, with each number on a new line for 10 lines total) -calls a function to determine how many lines are in the file -creates an array of the proper size -calls a function to read the file and populate the array -calls a function to write out the contents of the array in reverse order *output file should...
“Create a new Java Project” Project name = Lab3 “Use project folder as root for sources...
“Create a new Java Project” Project name = Lab3 “Use project folder as root for sources and class files” Finish Set your classpath for the workspace: Project > Properties > Java Build Path Libraries Add External Jars # if on Windows Choose algs4.jar and stdlib.jar from your user directory Documents/alg4 # else Choose algs4.jar and stdlib.jar from ~/alg4 (I hope you’re getting familiar with this sequence. From now on, I’ll just say “create new project LabX”, and you’ll need to...
Using JAVA For this assignment, you will analyze code that uses a file input stream and...
Using JAVA For this assignment, you will analyze code that uses a file input stream and a file output stream. Read through the linked Java™ code. In a Microsoft® Word document, answer the following questions: Could this program be run as is? If not, what is it lacking? Does this program modify the contents of an input stream? In what way? What are the results of running this code? ********************************************** CODE TO ANALYZE  ******************************************************** /********************************************************************** *   Program:   Datasort *   Purpose:   ...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a string, get a string from the user, open file, close file, read file, and allocate heap memory. You can use more macros than these if you like. Main Program File: Allocate 1024 bytes of dynamic memory and save the pointer to the area. The main program is a loop in which you ask the user for a filename. If they enter nothing for the...
Create a program that filters the data in a CSV file of product data based on...
Create a program that filters the data in a CSV file of product data based on some search word and prints the resulting output to a new file. Additionally, the program will print the number of items filtered to stdout. • Your program should take three arguments: an input file to process, an output file to save the results, and a search word. • If the output file already exists or cannot be opened, warn the user by printing "CANNOT...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
Each part of this lab will use the same input file, named “lab3-in.dat.” This file will...
Each part of this lab will use the same input file, named “lab3-in.dat.” This file will be located in the same directory as the executables (do not specify a path for the file in the Select statements). This file is a roster of animals in a travelling carnival. The record format for the file is as follows: Field Description Length Data Type Name 12 String Gender 1 String Species 15 String The end result of each part of this assignment...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used to find out which user account you are logged into?      . This command may come in handy in the following exercises. Ensure you are in your home directory of the student1 account. Use the echo command with output redirection to create a file called labfile4 and put the following text in this file: “This is the first line of labfile4”. Using the symbolic notation...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT