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...
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...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Hello, I am trying to create a Java program that reads a .txt file and outputs...
Hello, I am trying to create a Java program that reads a .txt file and outputs how many times the word "and" is used. I attempted modifying a code I had previously used for counting the total number of tokens, but now it is saying there is an input mismatch. Please help! My code is below: import java.util.*; import java.io.*; public class Hamlet2 { public static void main(String[] args) throws FileNotFoundException { File file = new File("hamlet.txt"); Scanner fileRead =...
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT