WickedProduction
10/13/2019 - 11:33 PM

Java IO - Using Filters and Creating Directories

package me.illuminatiproductions;

import java.io.File;
import java.io.FilenameFilter;

public class Main {

    public static void main(String[] args) {

        //Filters and listing files
        File web_files = new File("E:\\Development\\Web Development\\onlinereading2");
        System.out.println(web_files.isDirectory()); //see if its a folder

        //Make a filter to list only certain files
        FilenameFilter fileFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                if(name.endsWith(".json")){
                    return true;
                }else{
                    return false;
                }
            }
        };
        String[] files_list = web_files.list(fileFilter);
        //print out the files/folders
        for (int i = 0; i < files_list.length; i++){
            System.out.println(files_list[i]);
        }

        //How to get an array of actual file objects rather than names
        File video_files = new File("E:\\Videos\\Raw Recordings");
        File[] file_list = video_files.listFiles();
        for (int i = 0; i < file_list.length; i++){
            System.out.println(file_list[i].getName());
        }

        //Create new directories
        File file3 = new File("E:\\Videos\\Raw Recordings\\Battlefield V/Booty");
        file3.mkdir();

    }
}