Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package files;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Files
- {
- public static String root_dir = "/Users/kolinsol/Desktop/_temp_downloads";
- public static void main(String[] args)
- {
- File root_folder = new File(root_dir);
- dsCheck(root_dir);
- filrNamesList(root_folder);
- System.out.println(dirSize(root_folder));
- ArrayList<File> files = new ArrayList<>(Arrays.asList(root_folder.listFiles()));
- String[] file_names = fileNamesToString(root_folder.listFiles());
- for (String file_name : file_names)
- {
- System.out.println(file_name);
- }
- fileRenamer(root_folder.listFiles(),file_names);
- }
- public static void dsCheck(String path)
- {
- try
- {
- File ds_store = new File (path+"/.DS_Store");
- if (ds_store.exists())
- {
- ds_store.delete();
- System.out.println("ds_store deleted.");
- }
- else
- {
- System.out.println("no ds_store.");
- }
- }
- catch (NullPointerException e)
- {
- System.out.println("wrong filename.");
- }
- }
- public static void filrNamesList(File dir)
- {
- try
- {
- for (File child:dir.listFiles())
- System.out.println(child.toString());
- }
- catch (NullPointerException e)
- {
- System.out.println("the folder is empty.");
- }
- }
- public static int dirSize (File dir)
- {
- return dir.listFiles().length;
- }
- public static String[] fileNamesToString(File[] files)
- {
- String[] file_names = new String[files.length];
- for (int i=0; i<file_names.length;i++)
- {
- file_names[i]=files[i].toString();
- file_names[i] = file_names[i].replaceAll(root_dir+"/", "");
- file_names[i] = file_names[i].replace("[www.MP3Fiber.com]","");
- file_names[i] = file_names[i].replace("_", " ");
- file_names[i] = file_names[i].toLowerCase();
- file_names[i] = file_names[i].replace("prod", " p/ ");
- file_names[i] = file_names[i].replace("feat", " w/ ");
- file_names[i] = file_names[i].replace("production", " p/ ");
- file_names[i] = file_names[i].replace("featuring", " w/ ");
- file_names[i] = file_names[i].replace("ft", " w/ ");
- file_names[i] = file_names[i].replace(" ", " ");
- }
- return(file_names);
- }
- public static void fileRenamer(File[] files, String[] file_names)
- {
- if(files.length==file_names.length)
- {
- for(int i=0; i<files.length;i++)
- files[i].renameTo(new File(root_dir+"/"+file_names[i]));
- }
- else
- {
- System.out.println("wrong nuber of files.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement