Skip to content

Instantly share code, notes, and snippets.

@dennischen
Created August 21, 2014 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennischen/e7adc259052f6a6ca195 to your computer and use it in GitHub Desktop.
Save dennischen/e7adc259052f6a6ca195 to your computer and use it in GitHub Desktop.
scan and copy file to another folder
package com.zechster.yingzhun.ui;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import com.google.common.io.Files;
public class Test {
public static void main(String[] args) {
phase2();
}
public static void phase1(){
try{
File inFolder = new File("D://stickers");
File outpuFolder = new File("D://stickers2");
outpuFolder.mkdirs();
List<File> allFile = new LinkedList<File>();
List<File> queue = new LinkedList<File>();
queue.add(inFolder);
//scan
while(queue.size()>0){
File folder = queue.remove(0);
for(File f:folder.listFiles()){
if(f.isFile()){
allFile.add(f);
}else if(f.isDirectory()){
queue.add(f);
}
}
}
int i=0;
for(File file:allFile){
String name = file.getName();
try{
Integer.parseInt(name);
File outFile = new File(outpuFolder,i+".png");
System.out.println(i+">>>"+file +" to "+outFile);
Files.copy(file, outFile);
i++;
}catch(Exception x){
}
}
}catch(Exception x){
}
}
public static void phase2(){
try{
File inFolder = new File("D://stickers2");
File outpuFolder = new File("D://stickers3");
outpuFolder.mkdirs();
List<File> allFile = new LinkedList<File>();
List<File> queue = new LinkedList<File>();
queue.add(inFolder);
//scan
while(queue.size()>0){
File folder = queue.remove(0);
for(File f:folder.listFiles()){
if(f.isFile()){
allFile.add(f);
}else if(f.isDirectory()){
queue.add(f);
}
}
}
int i=0;
for(File file:allFile){
try{
File outFile = new File(outpuFolder,i+".png");
System.out.println(i+">>>"+file +" to "+outFile);
Files.copy(file, outFile);
i++;
}catch(Exception x){
}
}
}catch(Exception x){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment