Select a directory with Java WindowBuilder [closed]

1

Well first of all say that I'm learning and I was thinking of doing a kind of program where you would select a windows directory to later rename all the files inside according to a predefined pattern.

I do not pretend to be given the code, only if someone can tell me if it would be possible to do something like that and if it could be to tell me the way it would be done more or less .. I have seen that there is a class that is used to rename files, but I have no idea if you could select a directory to then act with your files.

PS: I intended to do it using WindowBuilder to make it more graphic, although if it has to be with another option, there's no problem.

    
asked by pacomaral 21.11.2016 в 14:41
source

1 answer

1

Try this. to obtain the Files of a specified directory, applying the filter. isFile , then the array is traversed to make the name change.     import java.io.File;     import java.io.FilenameFilter;     import java.util.Arrays;

public class Solution {
        public static void main(String[] args) {
        String path= "ruta";
        File file = new File(path);
        String[] directories = file.list(new FilenameFilter() {
          @Override
          public boolean accept(File current, String name) {
            return new File(current,name).isFile();
          }
        });
        System.out.println(Arrays.toString(directories));
        File var,newvar;int i=1;
        for (String directory : directories) {
            var = new File(path+directory);
            newvar= new File(path+"newName -"+i);
            var.renameTo(newvar);
        }
    }

}
    
answered by 21.11.2016 в 17:21