Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.FileNotFoundException;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unused import

import java.io.File;

import java.nio.file.DirectoryStream;
import java.nio.file.Files;
Expand All @@ -13,7 +13,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class MainApp {

private static Path getDirectory() throws IOException {
Expand All @@ -30,11 +29,24 @@ public static void main(String[] args) {
try {
Path dir = getDirectory();
DirectoryStream<Path> ds = Files.newDirectoryStream(dir);
logger.info(String.format("Looking at jobs in directory %s\n", dir));

// Iterate over all of the files in the directory, creating a job for each
for (Path entry : ds) {
Job job = new Job(entry.toFile());
logger.info(String.format("Job %d yields %d\n", job.getInput(), job.processJob()));
File jobFile = entry.toFile();
Job job = new Job(jobFile);
int processJob = job.processJob();

logger.info(String.format("Job %d yields %d\n", job.getInput(), processJob));
jobFile.delete();
logger.info(String.format("Deleted job %d\n", job.getInput()));
}
File jobsDir = new File(dir.toUri());
if (jobsDir.delete()) {
logger.info(String.format("Deleted job directory: %s\n", jobsDir.getName()));
} else {
System.out.println("Failed to delete the folder.");
logger.info(String.format("Failed to delete the jobs directory: %s\n", jobsDir.getName()));
}
} catch (IOException e) {
e.printStackTrace();
Expand Down