修改文件夹名称

 这个 需要自己测试在使用

package secode.lyp.cmmonclass;

import java.io.File;

/**
 * chartAt(int index),返回某索引的字符
 * trim(),返回字符串的副本,忽略前部空白和后部空白
 * concat()等价于“+”
 * equestIgnoreCase() 忽略大小写比较
 * substring(int beginIndex) 返回一个新的字符串,它是此字符串的beginIndex开始截取
 * substring(int beginIndex,end endIndex),
 * compareTo ()比较两个字符串的大小,负数 前面的小, 
 * endwith()
 * startWith()
 * contains()
 * int IndexOf(String str)
 * int IndexOf(String str,int fromIndex)
 * int lastIndexof(String str)
 * int lastIndexOf(String str,int formIndex)
 * String replace(char oldChar,char newChar)返回一个新的字符串,它是通过newChar替换此字符串中出现的所有oldChar得到的
 * String replace(CharSequence target,CharSequence replacement)使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串
 * String replaceAll(String regex,String replacement) 是要给定的replacement 替换此字符串所有匹配给定的正则表达式的字符串。
 * String replaceFirst(String regex,String replacement):使用给定的replacement替换此字符串匹配给定的正则表达式的第一个字符串。
 * boolean mathches
 * 
 * String[] split(String regex)
 * String[] split (String regex,int limit)
 */

// 修改文件夹名称
public class FileRename {
	
	public static void main(String[] args) {
//		String path = "";
		File fs = new File(path);
		File[] ls = fs.listFiles();
		for (File f:ls) {
		String name = f.getName();
		
		int si = name.indexOf("-");
		int li = name.lastIndexOf("-");
		
		CharSequence sub = name.subSequence(si, li+1);
		String tname = name.replace(sub,"-");
		String parent = f.getParent();
		String rename = parent+"\\"+tname;

		System.out.println(rename);
		
		boolean renameTo = f.renameTo(new File (rename));
		System.out.println(renameTo);
	}
	
	}
	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值