Google Drive API: list files with no parent

前端 未结 6 999
旧时难觅i
旧时难觅i 2020-12-30 08:47

The files in Google domain that I administer have gotten into a bad state; there are thousands of files residing in the root directory. I want to identify these files and mo

6条回答
  •  执笔经年
    2020-12-30 09:08

    Brute, but simple and it works..

        do {
            try {
                FileList files = request.execute();
    
                for (File f : files.getItems()) {
                    if (f.getParents().size() == 0) {
                            System.out.println("Orphan found:\t" + f.getTitle());
    
                    orphans.add(f);
                    }
                }
    
                request.setPageToken(files.getNextPageToken());
            } catch (IOException e) {
                System.out.println("An error occurred: " + e);
                request.setPageToken(null);
            }
        } while (request.getPageToken() != null
                && request.getPageToken().length() > 0);
    

提交回复
热议问题