批量为文件重命名

/**
	 * @param args
	 */
	public static void main(String[] args) {
		String destPath = "D:\\file\\20160307\\lys";
		batchRename(destPath);

	}

	/**
	 * 
	 * @param destPath
	 */
	private static void batchRename(String destPath) {
		File destFile = new File(destPath);
		File[] destFiles = destFile.listFiles();
		for (int i = 0; i < destFiles.length; i++) {
			File picFile = new File(destFiles[i].getPath());
			File[] picFiles = picFile.listFiles();
			// System.out.println(destFiles[i].getPath());
			for (int j = 0; j < picFiles.length; j++) {
				System.out.println(picFiles[j].getPath());
				String fileName = picFiles[j].getName().replace("lys", "lys_");
				picFiles[j]
						.renameTo(new File(destFiles[i].getPath(), fileName));

			}
		}
	}


比较简单,欢迎拍砖。

你可能感兴趣的:(java批量重命名文件)