From 202e600a1e878f4fcae677f06601fe75d133e335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Wed, 1 Jun 2022 00:38:54 +0200 Subject: [PATCH] Add project files --- .gitignore | 59 ++++++++++++++++++++ pom.xml | 65 ++++++++++++++++++++++ src/main/java/org/example/Renamer.java | 72 +++++++++++++++++++++++++ src/main/resources/META-INF/MANIFEST.MF | 0 4 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/org/example/Renamer.java create mode 100644 src/main/resources/META-INF/MANIFEST.MF diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f73c6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,59 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ +target/ + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3a5fd6e --- /dev/null +++ b/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + org.example + Renamer + 1.0-SNAPSHOT + jar + + + + org.xerial + sqlite-jdbc + 3.32.3.2 + + + + io.github.eamonnmcmanus + serialysis + 0.9 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + + + + org.apache.maven.plugins + maven-assembly-plugin + + + create-my-bundle + package + + single + + + + jar-with-dependencies + + + + org.example.Renamer + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/example/Renamer.java b/src/main/java/org/example/Renamer.java new file mode 100644 index 0000000..0ef8b5a --- /dev/null +++ b/src/main/java/org/example/Renamer.java @@ -0,0 +1,72 @@ +package org.example; + +import java.io.File; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Renamer +{ + + /* + this simple and inefficient program was made to rename files in a folder that were numbered incorrectly. + the files had the correct number in their name, but since most OSes use alphabetical order, it was not like this: + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10... + but like this: + 1, 10, 11, 12-19, 100, 101, 102... 2, 20, 21-29, 200, 201, 202... + + this is easily fixed by adding zeros before the actual number, up to the number of needed digits: + 001, 002, 003, 004... 010, 011... 020, 021... 100, 101... + */ + + public static String path = "D:\\CD 2021\\foto"; + + public static void main(String[]args) + { + Set listaFoto = listFilesUsingJavaIO(path); + System.out.println(listaFoto.toString()); + + for(String currentFile : listaFoto) + { + System.out.println("Orig: " + currentFile); + System.out.println("Nums: " + currentFile.replaceAll("[^\\d]", "")); + + String onlyNumbers = currentFile.replaceAll("[^\\d]", ""); + String everythingElse = currentFile.replaceAll("[\\d]", ""); + if(onlyNumbers.length() >= 3 || onlyNumbers.length() == 0) continue; + + String newName = ""; + + if(onlyNumbers.length() == 2) + { + System.out.println("size 2"); + newName = "0" + onlyNumbers; + } + else + if(onlyNumbers.length() == 1) + { + System.out.println("size 1"); + newName = "00" + onlyNumbers; + } + else newName = onlyNumbers; + + newName = newName + everythingElse; + + System.out.println("New: " + newName); + + File original = new File(path + "\\" + currentFile); + File destination = new File(path + "\\" + newName); + + original.renameTo(destination); + + } + + } + + public static Set listFilesUsingJavaIO(String dir) { + return Stream.of(new File(dir).listFiles()) + .filter(file -> !file.isDirectory()) + .map(File::getName) + .collect(Collectors.toSet()); + } +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29