天天看点

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

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

首先需要将所有文档放在同一个文件夹中,并得到该文件夹的存放的路径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());   

            }   

        }   

    }   

}   

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

继续阅读