- import java.io.*;
- import java.util.*;
- public class GCCbin {
- public static void main(String[] args) {
- LinkedList<String> folderList = new LinkedList<String>();
- folderList.add(".");
- StringBuilder sb = new StringBuilder(256);
- sb.append("xterm -e ");
- boolean first = true;
- while (folderList.size() > 0) {
- File file = new File(folderList.poll());
- File[] files = file.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- folderList.add(files[i].getPath());
- } else {
- if (files[i].getName().substring(2).contains(".")
- && (files[i].getName().substring(
- files[i].getName().lastIndexOf("."))
- .equals(".c") || files[i].getName().substring(2).substring(
- files[i].getName().lastIndexOf(".")).equals(".cpp")) {
- if (!first)
- sb.append(" & ");
- first = false;
- sb.append("gcc """
- + files[i].getAbsoluteFile()
- + """ -o """
- + files[i].getAbsolutePath().substring(
- 0,
- files[i].getAbsolutePath().lastIndexOf(
- "."))+"""");
- }
- }
- }
- try {
- Runtime.getRuntime().exec(sb.toString());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/121120137087.html
来源: http://www.codesnippet.cn/detail/121120137087.html