Last active
June 20, 2024 05:56
-
-
Save iolo/9e93082cd78b9ec3d948ffd43ec32c8d to your computer and use it in GitHub Desktop.
맥에서 만들어져서 풀어쓰기(NFD) 파일 이름을 모아쓰기(NFC) 파일 이름으로 변경(java버전)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.text.Normalizer; | |
import java.util.Set; | |
public class NFC { | |
public static void scanFiles(File dir, boolean recursive, boolean dryRun) { | |
for (File file: dir.listFiles()) { | |
var oldName = file.getName(); | |
var newName = Normalizer.normalize(file.getName(), Normalizer.Form.NFC); | |
if (!oldName.equals(newName)) { | |
System.out.println(file.getPath() + " -> " + newName); | |
if (!dryRun) { | |
file.renameTo(new File(dir, newName)); | |
} | |
} | |
if (recursive && file.isDirectory() && file.canRead()) { | |
scanFiles(file, true, dryRun); | |
} | |
} | |
} | |
public static void main(String ...args) { | |
Set<String> argSet = Set.of(args); | |
File baseDir = new File(argSet.stream().filter(it->!it.startsWith("-")).findFirst().orElse(".")); | |
boolean dryRun = argSet.contains("--dry-run") || argSet.contains("-n"); | |
boolean recursive = argSet.contains("--recursive") || argSet.contains("-r"); | |
NFC.scanFiles(baseDir, recursive, dryRun); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment