08-01
18
批量更改文件名
作者:Java伴侣 日期:2008-01-18
复制内容到剪贴板 程序代码
import java.io.*;
import java.io.*;
public class FileRename {
private File dir;
private String absolute;
public FileRename(File dir) throws Exception
{
if(dir.isDirectory())
{
this.dir = dir;
dir.getAbsolutePath()
}
else
{
throw new Exception("err dir");
}
}
public boolean Rename(String filename, int increment) {
int i = 0;
String temp[] = dir.list();
for (String s : temp) {
File f = new File(absolute + File.pathSeparator + "s");
if (f.isFile()) {
f.renameTo(new File(absolute + File.pathSeparator + filename
+ String.valueOf(i)));
i = i + increment;
}
}
}
public static void main(String args[]) throws Exception
{
FileRename fr = new FileRename("c:\windows");
fr.Rename("debug.exe",1);
}
}
import java.io.*;
public class FileRename {
private File dir;
private String absolute;
public FileRename(File dir) throws Exception
{
if(dir.isDirectory())
{
this.dir = dir;
dir.getAbsolutePath()
}
else
{
throw new Exception("err dir");
}
}
public boolean Rename(String filename, int increment) {
int i = 0;
String temp[] = dir.list();
for (String s : temp) {
File f = new File(absolute + File.pathSeparator + "s");
if (f.isFile()) {
f.renameTo(new File(absolute + File.pathSeparator + filename
+ String.valueOf(i)));
i = i + increment;
}
}
}
public static void main(String args[]) throws Exception
{
FileRename fr = new FileRename("c:\windows");
fr.Rename("debug.exe",1);
}
}
评论: 0 | 引用: 0 | 查看次数: 661
发表评论