What are all the ways to traverse directory trees?

后端 未结 7 1113
挽巷
挽巷 2021-01-02 04:13

How do you traverse a directory tree in your favorite language?

What do you need to know to traverse a directory tree in different operating systems? On different f

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 04:37

    In Java:

    Recursion is useful here. Following is a Java code snippet that's been all over the Internet for ages. Not sure who deserves the credit for it.

    // Process all files and directories under dir
    
        public static void visitAllDirsAndFiles(File dir) {
    
            process(dir);  //do something useful with the file or dir
    
            if (dir.isDirectory()) {
                String[] children = dir.list();
                for (int i=0; i

提交回复
热议问题