package FolderSplit;

import java.io.File;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

public class FileCollector {
    List<FileInfo> files;
    
    public void scanDirectory(File path) {
        if (path.isDirectory()) {
            files = new ArrayList<FileInfo>();
            for (File file : path.listFiles()) {
                files.add(new FileInfo(file));
            }
        } else {
            throw new InvalidParameterException("Path must be a directory.");
        }
    }

    public List<FileInfo> getFileInfos() {
        return new ArrayList<FileInfo>(files);
    }

    public List<FileInfo> getFileInfos(String regex) {
        ArrayList<FileInfo> list = new ArrayList<FileInfo>();
        for (FileInfo file : files) {
            if (file.name.matches(regex)) {
                list.add(file);
            }
        }
        return list;
    }
}
