Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Gradle build configuration for specific lab module / exercise
|
||||
*/
|
||||
// enabled plugins
|
||||
plugins {
|
||||
id 'java'
|
||||
// Apply the application plugin to add support for building a CLI application.
|
||||
id 'application'
|
||||
}
|
||||
|
||||
// Project/Module information
|
||||
description = 'Lab05 FileAttributes Solution'
|
||||
group = 'ch.zhaw.prog2'
|
||||
version = '2022.1'
|
||||
|
||||
// Dependency configuration
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
}
|
||||
|
||||
// Configuration for Application plugin
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'ch.zhaw.prog2.io.DirList'
|
||||
}
|
||||
|
||||
// enable console input when running with gradle
|
||||
run {
|
||||
standardInput = System.in
|
||||
}
|
||||
|
||||
|
||||
// Java plugin configuration
|
||||
java {
|
||||
// By default the Java version of the gradle process is used as source/target version.
|
||||
// This can be overridden, to ensure a specific version. Enable only if required.
|
||||
// sourceCompatibility = JavaVersion.VERSION_17 // ensure Java source code compatibility
|
||||
// targetCompatibility = JavaVersion.VERSION_17 // version of the created byte-code
|
||||
|
||||
// Java compiler specific options
|
||||
compileJava {
|
||||
// source files should be UTF-8 encoded
|
||||
options.encoding = 'UTF-8'
|
||||
// for more options see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package ch.zhaw.prog2.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class DirList {
|
||||
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static void main(String[] args) {
|
||||
String pathName = args.length >= 1 ? args[0] : ".";
|
||||
File file = new File(pathName);
|
||||
if (file.isDirectory()) {
|
||||
for (File subFile : file.listFiles()) {
|
||||
System.out.println(printFileMetadata(subFile));
|
||||
}
|
||||
} else {
|
||||
System.out.println(printFileMetadata(file));
|
||||
}
|
||||
}
|
||||
|
||||
public static String printFileMetadata(File file) {
|
||||
return String.format("%c%c%c%c%c %s %8d %s",
|
||||
file.isDirectory()? 'd' : 'f',
|
||||
file.canRead()? 'r' : '-',
|
||||
file.canWrite()? 'w' : '-',
|
||||
file.canExecute()? 'x' : '-',
|
||||
file.isHidden()? 'h' : '-',
|
||||
dateFormat.format(file.lastModified()),
|
||||
file.length(),
|
||||
file.getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user