将指定目录下面得所有文件名从大写转化为小写

类别:Java 点击:0 评论:0 推荐:

用Java写得小程序,保存在这里吧···

import java.io.*;

public class changefilename
{
 public static void main(String[] args)
 {
  System.out.println("->->->Main Begin...");
  String path = new String("E:\\");
  changepathname(path);
  System.out.println("->->->Main End...");
 }
 
 public static void changepathname(String path)
 {
  System.out.println("->->->changepathname Begin...");
  File d = new File(path);
  //取得当前文件夹下所有文件和目录的列表
  File lists[] = d.listFiles();
  String pathss = new String("");
  //对当前目录下面所有文件进行检索
  for(int i = 0; i < lists.length; i ++)
  {
   if(lists[i].isFile())
   {
    String filename = lists[i].getName();
    filename = upCase(filename);
    String toName = new String(path + filename);
    File tempf = new File(toName);
    
    lists[i].renameTo(tempf); 
    System.out.println("new fullfilename is:" + toName);   
   }
   else
   {
    pathss = path;
    //进入下一级目录
    pathss = pathss + lists[i].getName() + "\\";    
    //递归遍历所有目录
    changepathname(pathss);    
   }
  }  
  System.out.println("->->->changepathname End...");
 }
 
 public static String upCase(String filename)
 {
  System.out.println("->->->upCase Begin...");
  String tempstr = new String("");
  char tempch = ' ';
  for(int i = 0; i < filename.length(); i ++)
  {
   tempch = filename.charAt(i);
   if(64 < filename.charAt(i)&& filename.charAt(i) < 91)//是大写字母
    tempch += 32;
   tempstr +=  tempch;
  }
  System.out.println("new filename is:" + tempstr);
  System.out.println("->->->upCase End...");
  return  tempstr;
 }
 
}

本文地址:http://com.8s8s.com/it/it12770.htm