ルートディレクトリ内のファイルとフォルダのリストの問合せ
-
13-12-2019 - |
質問
ルートディレクトリにファイルやフォルダのリストを並べ替えずに、すべてのファイルを並べ替える必要があります。これを行うクエリはありますか?
解決
ルートフォルダには、 "root"という名前の特別なエイリアスでアドレス指定することもできますので、次のクエリを使用してルート内のすべてのファイルとフォルダを取得できます。
https://www.googleapis.com/drive/v2/files?q='root' in parents
.
クライアントライブラリの1つを使用しない場合はURLをエスケープすることを忘れないでください(自動的にそれを大事にします)。
検索クエリ言語の詳細については、 https://developers.google.com/drive/search-parametersters
他のヒント
このコードは、ルートディレクトリのすべてのファイルとフォルダを表示します。このコードをコピーして貼り付けるだけで、すべてのルートのファイルとフォルダが表示されます。
List<File> result = new ArrayList<File>();
Files.List request = null;
try {
request = mService.files().list();
FileList files = request.setQ("'root' in parents and trashed=false").execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
}
catch (IOException e)
{
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
//Print out all the files and folder of root Directory
for(File f:result)
{
System.out.println("recvd data are: "+f.getTitle());
}
. Googleドライブv3 リファレンスドキュメント DriveClientオブジェクトを作成するのに役立ちます。
バックグラウンドスレッド(Android)の以下の方法を実行します。
注:必須スコープ許可 "drivescopes.drive"
protected String[] getListChildren(String parentId) throws Exception {
String[] children = null;
parentId = parentId == null ? "root" : parentId;
String fileQuery = "'" + parentId + "' in parents and trashed=false";
FileList files = driveService.files().list().setQ(fileQuery).execute();
List<String> fileNames = new ArrayList<String>();
for (File file : files.getFiles()) {
fileNames.add(file.getName());
}
children = fileNames.toArray(new String[0]);
return children;
}
. 所属していません StackOverflow