diff --git a/.idea/artifacts/copy_images_jar.xml b/.idea/artifacts/copy_images_jar.xml new file mode 100644 index 0000000..105a0d8 --- /dev/null +++ b/.idea/artifacts/copy_images_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/copy_images_jar + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..08164ca --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/copy-images.iml b/copy-images.iml new file mode 100644 index 0000000..fb8e866 --- /dev/null +++ b/copy-images.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5ee19cb --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Main + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..397d6ce --- /dev/null +++ b/src/Main.java @@ -0,0 +1,59 @@ +import org.apache.commons.io.FileUtils; + +import javax.imageio.IIOException; +import java.io.File; +import java.io.IOException; +import java.util.Objects; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // Start here... + Scanner sc = new Scanner(System.in); + System.out.println("Enter a path: "); + String filePath = sc.nextLine(); + System.out.println("debug mode on? (Y/N)"); + String debugChoice = sc.nextLine().trim().toLowerCase(); + boolean debug = debugChoice.equals("y"); + listDirs(new File(filePath), debug, ""); + } + + public static void listDirs(File file, boolean debug, String directoryName) { + if (file.isFile()) { //stopping condition + String name = file.getName().toLowerCase(); + try { + + + if (!directoryName.endsWith("/") && !directoryName.isEmpty()) directoryName += "/"; + // check if image + if (name.endsWith(".jpg") || name.endsWith(".png") || name.endsWith(".jpeg") || name.endsWith(".tiff") || name.endsWith(".gif")) { + if (debug) System.out.println("checking file " + file.getName()); + FileUtils.copyFile(file, new File("images/" + directoryName + file.getName())); + } else if (name.endsWith(".mp4") || name.endsWith(".wmv") || name.endsWith(".mov") || name.endsWith(".avi")) { //check if video + if (debug) System.out.println("checking file " + file.getName()); + FileUtils.copyFile(file, new File("videos/" + directoryName + file.getName())); + } else if (name.endsWith(".mp3") || name.endsWith(".wav")) { //check if audio file + if (debug) System.out.println("checking file " + file.getName()); + FileUtils.copyFile(file, new File("music/" + directoryName + file.getName())); + } else if (name.endsWith(".doc") || name.endsWith(".docx") || name.endsWith(".rtf")) { + if (debug) System.out.println("checking file " + file.getName()); + FileUtils.copyFile(file, new File("docs/" + directoryName + file.getName())); + } + } catch (IOException e) { + System.out.println("something went wrong: " + e.getMessage()); + } + } + + if (file.isDirectory()) { + if (file.listFiles() != null) { + if (!directoryName.endsWith("/")) directoryName += "/"; + for (File file1 : Objects.requireNonNull(file.listFiles())) { + listDirs(file1, debug, directoryName + file.getName()); + } + + } + + } + } +} diff --git a/testdir/images.jpg b/testdir/images.jpg new file mode 100644 index 0000000..b363e8f Binary files /dev/null and b/testdir/images.jpg differ diff --git a/testdir/test2/img.png b/testdir/test2/img.png new file mode 100644 index 0000000..e69de29 diff --git a/testdir/test2/test3/img2.png b/testdir/test2/test3/img2.png new file mode 100644 index 0000000..e69de29