在日常工作中,當我們需要批量擷取文檔的檔案名資訊時,可以通過程式完成,減輕了人工的工作量。
首先需要将所有文檔放在同一個檔案夾中,并得到該檔案夾的存放的路徑path,然後在利用程式擷取資訊。我們采用java語言,具體實作代碼如下:
import java.io.File;
public class Test{
public static void main(String[] args) {
// This is the path where the file's name you want to take.
String path = "C://Users//Administrator//Desktop//sjk";
getFile(path);
}
private static void getFile(String path){
// get file list where the path has
File file = new File(path);
// get the folder list
File[] array = file.listFiles();
for(int i=0;i<array.length;i++){
if(array[i].isFile()){
// only take file name
System.out.println(array[i].getName());
// take file path and name
System.out.println("#####" + array[i]);
// take file path and name
System.out.println("*****" + array[i].getPath());
}else if(array[i].isDirectory()){
getFile(array[i].getPath());
}
}
}
}
此時我們有多個輸出結果懿滿足不同的輸出要求。