批处理文件工具
引言:不知道小伙伴们平时在生活中处理许多文件的时候有没有遇到过需要处理很多文件名的时候,在Window系统中没有批处理的重命名文件的功能,而MAC OX有这样的小功能,因此制作了简易的批处理文件工具。
MainFrame
package batchfile;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;
public class MainFrame extends JFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建窗体
JFrame frame = new JFrame("BatchFiles");
// 设置布局为null--清空布局
frame.setLayout(null);
// 增加标签
JLabel dirPath = new JLabel("dirPath:");
dirPath.setBounds(15, 25, 50, 30);
frame.add(dirPath);
JTextField dirPathFileld = new JTextField();
dirPathFileld.setBounds(70, 25, 390, 30);
frame.add(dirPathFileld);
JButton browser = new JButton("Browser");
browser.setBounds(465, 25, 75, 30);
frame.add(browser);
JLabel oldDirName = new JLabel("oldDir:");
oldDirName.setBounds(15, 60, 75, 30);
frame.add(oldDirName);
JTextField oldDirField = new JTextField();
oldDirField.setBounds(80, 60, 120, 30);
frame.add(oldDirField);
JLabel label = new JLabel("=>");
label.setBounds(205, 60, 50, 30);
frame.add(label);
JTextField newDirField = new JTextField();
newDirField.setBounds(235, 60, 120, 30);
frame.add(newDirField);
JLabel newDirName = new JLabel(":newDir");
newDirName.setBounds(365, 60, 75, 30);
frame.add(newDirName);
// 设置撤回按钮
JButton recallDirButton = new JButton("RecallDir");
recallDirButton.setBounds(440, 60, 100, 30);
frame.add(recallDirButton);
recallDirButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String filePath = dirPathFileld.getText();
String oldTonew = oldDirField.getText();
String recallPathString = FixFileName(filePath, oldTonew);
dirPathFileld.setText(recallPathString);
}
});
JLabel oldFileName = new JLabel("oldFile:");
oldFileName.setBounds(15, 100, 75, 30);
frame.add(oldFileName);
JTextField oldFileField = new