public static void renameAllFiles(String path, boolean needLowerCase) {
try {
File file = new File(path);
if (!file.exists())
return;
if (!file.isDirectory())
return;
String[] tempList = file.list();
File temp = null;
File destinationFile = null;
for (int i = 0; i < tempList.length; i++) {
System.out.println(tempList[i]);
//防止文件路径中有空格,生成要重命名的文件对象
if (path.endsWith(File.separator))
temp = new File(path + tempList[i]);
else
temp = new File(path + File.separator + tempList[i]);
//设定修改的规则:大写或者小写
if (needLowerCase)
tempList[i] = tempList[i].toLowerCase();
else
tempList[i] = tempList[i].toUpperCase();
//根据规则,产生虚拟的新文件对象
if (path.endsWith(File.separator))
destinationFile = new File(path + tempList[i]);
else
destinationFile =
new File(path + File.separator + tempList[i]);
if (temp.isFile())
temp.renameTo(destinationFile);
if (temp.isDirectory())
renameAllFiles(path + tempList[i], needLowerCase);
} }
catch (Exception e) {
System.out.println(e);
} } public static void renameAllFiles(String path, boolean needLowerCase) {
try {
File file = new File(path);
if (!file.exists())
return;
if (!file.isDirectory())
return;
String[] tempList = file.list();
File temp = null;
File destinationFile = null;
for (int i = 0; i < tempList.length; i++) {
System.out.println(tempList[i]);
//防止文件路径中有空格,生成要重命名的文件对象
if (path.endsWith(File.separator))
temp = new File(path + tempList[i]);
else
temp = new File(path + File.separator + tempList[i]);
//设定修改的规则:大写或者小写
if (needLowerCase)
tempList[i] = tempList[i].toLowerCase();
else
tempList[i] = tempList[i].toUpperCase();
//根据规则,产生虚拟的新文件对象
if (path.endsWith(File.separator))
destinationFile = new File(path + tempList[i]);
else
destinationFile =
new File(path + File.separator + tempList[i]);
if (temp.isFile())
temp.renameTo(destinationFile);
if (temp.isDirectory())
renameAllFiles(path + tempList[i], needLowerCase);
} }
catch (Exception e) {
System.out.println(e);
} }
以上是重命名的代码,修改一下就是删除的