批量获取Word文档的文件名信息

来源:互联网 发布:英语文献翻译软件 编辑:程序博客网 时间:2024/06/05 00:18

在日常工作中,当我们需要批量获取文档的文件名信息时,可以通过程序完成,减轻了人工的工作量。

首先需要将所有文档放在同一个文件夹中,并得到该文件夹的存放的路径path,然后在利用程序获取信息。我们采用java语言,具体实现代码如下:


import java.io.File;    
  
/**  
 * @author yinxm  
 * @version 1.0 2005/06/17  
 *   
 * This class can take file's path and file's name;  
 * you must give the path where you want to take the 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());   
            }   
        }   
    }   
}   

此时我们有多个输出结果懿满足不同的输出要求。

原创粉丝点击