zondag 22 juli 2012

Howto create a set of files on the fly (after the folders)


Intro
In this blog I would like to show what is the easiest way in java to create a set of files after we create the folders see my previous post howto create set of folders on the fly.

The problem.

We determined the folders we want to rename and fill them up with files. The first part I described this part is al logical follow up.

The solution

The filter we are going to use at this point, is at file level The filter would look something like this:

package com.hanichi.webshop.controller.image.resize;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.IOException;

public class ImageFilter implements FileFilter {
private final static String FILE_NAME_POST_FIX = "png";

@Override
public boolean accept(File pathname) {

return pathname.getAbsolutePath().endsWith(FILE_NAME_POST_FIX);
}

}

for (File folder : imagesFolders) {
   ImageFilter imageFilter = new ImageFilter();
File[] images = new File(folder.getAbsolutePath()).listFiles(imageFilter);
   String path = image.getAbsolutePath();
for (File image : images) {
     if(image.isFile()){
       String filePath =path.replace(IMAGES, ICONS); 
      }
}
}
}

This is a very fast way to code in short time how to copy and rename files.

Have fun!

Geen opmerkingen:

Een reactie posten