package com.lkl.filerename;
/**
* 将原路径下所有的文件移动到目标路径下
* 文件夹不移动
*/
import java.io.File;public class FileMove {
private String filePath;//原路径
private String targetPath;//目标路径
public static int number = 0;
private String filer = "avi";//只移该种文件
public FileMove(String filePath,String targetPath){
this.filePath = filePath;
this.targetPath = targetPath;
}
public void move(){
File filePathFile = new File(filePath);
move(filePathFile);
}
private void move(File cpath){
if(cpath!=null && cpath.isDirectory()){
String[] cfileList = cpath.list();
for(String fpath : cfileList){
File temFile = new File(cpath.getAbsolutePath()+File.separator+fpath);
move(temFile);
}
}else if(cpath!=null && cpath.isFile()){
try{
if(cpath.getName().indexOf(filer) == (cpath.getName().length()-filer.length())){
}else{
cpath.renameTo(new File(targetPath+File.separator+cpath.getName()));
number++;
}
}catch(Exception e){
System.out.println(cpath.getAbsolutePath()+cpath.getName()+"@@@"+e.getMessage());
}
}
} public String getFiler() {
return filer;
} public void setFiler(String filer) {
this.filer = filer;
}
}以上代码用来迁移avi文件,嘿嘿大家懂得。递归 文件迁移 电影移动
/**
* 将原路径下所有的文件移动到目标路径下
* 文件夹不移动
*/
import java.io.File;public class FileMove {
private String filePath;//原路径
private String targetPath;//目标路径
public static int number = 0;
private String filer = "avi";//只移该种文件
public FileMove(String filePath,String targetPath){
this.filePath = filePath;
this.targetPath = targetPath;
}
public void move(){
File filePathFile = new File(filePath);
move(filePathFile);
}
private void move(File cpath){
if(cpath!=null && cpath.isDirectory()){
String[] cfileList = cpath.list();
for(String fpath : cfileList){
File temFile = new File(cpath.getAbsolutePath()+File.separator+fpath);
move(temFile);
}
}else if(cpath!=null && cpath.isFile()){
try{
if(cpath.getName().indexOf(filer) == (cpath.getName().length()-filer.length())){
}else{
cpath.renameTo(new File(targetPath+File.separator+cpath.getName()));
number++;
}
}catch(Exception e){
System.out.println(cpath.getAbsolutePath()+cpath.getName()+"@@@"+e.getMessage());
}
}
} public String getFiler() {
return filer;
} public void setFiler(String filer) {
this.filer = filer;
}
}以上代码用来迁移avi文件,嘿嘿大家懂得。递归 文件迁移 电影移动
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货