فایل هایی با برچسب یا مقدار فیلد خاص را جستجو کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
در این صفحه نحوه جستجوی فایلهایی با برچسب یا مقدار فیلد خاص توضیح داده شده است.
انواع فیلد برچسب
فیلدهای برچسب Google Drive به شدت تایپ می شوند و هر نوع از فهرست بندی و معنای جستجوی متفاوتی پشتیبانی می کند. جدول زیر انواع داده های موجود را نشان می دهد.
تایپ کنید
گزینه های نوع برچسب
پشتیبانی از اپراتورهای جستجو
متن
TextOptions
is null, is not null, =, contains, starts with
متن طولانی
LongTextOptions
is null, is not null, contains
عدد صحیح
IntegerOptions
is null, is not null, =, !=, <, >, <=, >=
تاریخ
گزینه های تاریخ
is null, is not null, =, !=, <, >, <=, >=
انتخاب
SelectionOptions
is null, is not null, =, !=
کاربر
UserOptions
is null, is not null, =, !=
لیست انتخاب
SelectionOptions (با max_entries > 1)
is null, is not null, in, not in
لیست کاربر
گزینه های کاربر (با حداکثر ورودی > 1)
is null, is not null, in, not in
نمونه ها را جستجو کنید
1. جستجو بر اساس وجود یک برچسب یا فیلد
می توانید مواردی را جستجو کنید که برچسب خاصی در آنها اعمال شده است (یا نشده است):
'labels/contract' in labels
not 'labels/contract' in labels
همچنین می توانید مواردی را جستجو کنید که فیلد خاصی تنظیم شده است (یا نشده است):
labels/contract.comment IS NOT NULL
labels/contract.comment IS NULL
2. جستجو بر اساس فیلدهای تک ارزشی
می توانید عبارت های جستجو را برای مطابقت با مقادیر فیلد مورد انتظار بنویسید. جدول زیر پرس و جوهای فیلد معتبر را نشان می دهد:
چیزی که می خواهید پرس و جو کنید
رشته پرس و جو
مواردی که نظر روی "سلام" تنظیم شده است
labels/contract.comment = 'hello'
فایل هایی که نظر با "سلام" شروع می شود
labels/contract.comment STARTS WITH 'hello'
فایل هایی که وضعیت در آنها اجرا می شود
labels/contract.status = 'executed'
فایل هایی که وضعیت در آنها اجرا نمی شود
labels/contract.status != 'executed'
فایل هایی که execution_date قبل از تاریخ خاصی است
labels/contract.execution_date < '2020-06-22'
فایل هایی که value_usd (عدد صحیح) کمتر از یک مقدار خاص است
labels/contract.value_usd < 2000
فایل هایی که در آنها client_contact روی یک آدرس ایمیل خاص تنظیم شده است
3. جستجو بر اساس فیلدهای دارای فیلدهای چند ارزشی (مانند ListOptions.max_entries > 1)
فیلدهایی که چندین مقدار را پشتیبانی می کنند فقط با استفاده از عملگر IN قابل جستجو هستند:
' EMAIL_ADDRESS ' IN labels/project.project_leads
NOT ' EMAIL_ADDRESS ' IN labels/project.project_leads
مثال
نمونه کد زیر نحوه استفاده از یک یا چند labelId برای فهرست کردن همه فایلها با برچسب یا مقدار فیلد خاص از منبع فایل Drive نشان میدهد. همچنین از روش files.list استفاده می کند. بدنه درخواست باید خالی باشد.
اگر میخواهید labelInfo در پاسخ اضافه کنید، باید مشخص کنید:
includeLabels به عنوان لیست شناسه های جدا شده با کاما.
labelInfo در پارامتر fields برای نشان دادن اینکه می خواهید labelInfo در داخل includeLabels برگردانده شود.
در صورت موفقیت آمیز بودن، بدنه پاسخ حاوی لیستی از فایل ها است.
جاوا
List<File>fileList=driveService.files().list().setIncludeLabels("LABEL_1_ID,LABEL_2_ID").setFields("items(labelInfo, id)").setQ("'labels/LABEL_1_ID' in labels and 'labels/LABEL_2_ID' in labels").execute().getItems();
پایتون
file_list=drive_service.files().list(includeLabels="LABEL_1_ID,LABEL_2_ID",q="'labels/LABEL_1_ID' in labels and 'labels/LABEL_2_ID' in labels",fields="items(labelInfo, id)").execute();
Node.js
/*** Search for Drive files with specific labels* @return{obj} file list with labelInfo**/asyncfunctionsearchForFileWithLabels(){// Get credentials and build service// TODO (developer) - Use appropriate auth mechanism for your appconst{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive'});constservice=google.drive({version:'v3',auth});try{constfileList=awaitservice.files.list({includeLabels:'LABEL_1_ID,LABEL_2_ID',q:'\'labels/LABEL_1_ID\' in labels and \'labels/LABEL_2_ID\' in labels',fields:'files(labelInfo, id)',});returnfile;}catch(err){// TODO (developer) - Handle errorthrowerr;}
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Search for files with a specific label or field value\n\nThis page describes how to search for files with a specific label or field value\napplied.\n\nLabel field types\n-----------------\n\nGoogle Drive label fields are strongly typed with each type supporting\ndifferent indexing and search semantics. The following table shows the available\ndata types.\n\n| Type | Label type options | Supported search operators |\n|----------------|------------------------------------------|--------------------------------------------------|\n| Text | TextOptions | `is null, is not null, =, contains, starts with` |\n| Long Text | LongTextOptions | `is null, is not null, contains` |\n| Integer | IntegerOptions | `is null, is not null, =, !=, \u003c, \u003e, \u003c=, \u003e=` |\n| Date | DateOptions | `is null, is not null, =, !=, \u003c, \u003e, \u003c=, \u003e=` |\n| Selection | SelectionOptions | `is null, is not null, =, !=` |\n| User | UserOptions | `is null, is not null, =, !=` |\n| Selection List | SelectionOptions (with max_entries \\\u003e 1) | `is null, is not null, in, not in` |\n| User List | UserOptions (with max_entries \\\u003e 1) | `is null, is not null, in, not in` |\n\n### Search examples\n\n| **Note:** In the examples below, readable strings are used for clarity. Actual resource names and field IDs must be used instead. For example, `labels/contract.execution_date` might look something like this: `labels/837d7f5de85137b86e52.491d`.\n\n**1. Search based on the presence of a label or field**\n\nYou can search for items where a specific label has (or has not) been applied:\n\n- `'labels/contract' in labels`\n- `not 'labels/contract' in labels`\n\nYou can also search for items where a specific field has (or has not) been set:\n\n- `labels/contract.comment IS NOT NULL`\n- `labels/contract.comment IS NULL`\n\n| **Note:** Searching for files without any fields set returns items that the label has not been applied to. You can combine the queries above to find items where the label is applied, but doesn't contain a value for a specific field: `'labels/contract' in labels AND labels/contract.comment IS NULL`.\n\n**2. Search based on single-valued fields**\n\nYou can write search queries to match expected field values. The following table\nshows the valid field queries:\n\n| What you want to query | Query string |\n|---------------------------------------------------------------|---------------------------------------------------------|\n| Items where comment is set to \"hello\" | `labels/contract.comment = 'hello'` |\n| Files where comment starts with \"hello\" | `labels/contract.comment STARTS WITH 'hello'` |\n| Files where status is executed | `labels/contract.status = 'executed'` |\n| Files where status is not executed | `labels/contract.status != 'executed'` |\n| Files where execution_date is before a specific date | `labels/contract.execution_date \u003c '2020-06-22'` |\n| Files where value_usd (integer) is less than a specific value | `labels/contract.value_usd \u003c 2000` |\n| Files where client_contact is set to a specific email address | `labels/contract.client_contact = 'alex@altostrat.com'` |\n\n**3. Search based on fields with multivalued fields (such as\nListOptions.max_entries \\\u003e 1)**\n\nFields that support multiple values can only be queried using the IN operator:\n\n- `'`\u003cvar translate=\"no\"\u003eEMAIL_ADDRESS\u003c/var\u003e`' IN labels/project.project_leads`\n- `NOT '`\u003cvar translate=\"no\"\u003eEMAIL_ADDRESS\u003c/var\u003e`' IN labels/project.project_leads`\n\nExample\n-------\n\nThe following code sample shows how to use one or more `labelId` to list all\nfiles with a specific label or field value from a Drive [file\nresource](/workspace/drive/labels/reference/rest/v2/labels). It also uses the\n[`files.list`](/workspace/drive/api/v2/reference/files/list) method. The request body must\nbe empty.\n\nIf you want to include `labelInfo` in the response, you also must specify:\n\n- [`includeLabels`](/workspace/drive/api/reference/rest/v2/files/get#query-parameters)\n as a comma-separated list of IDs.\n\n- `labelInfo` in the `fields` parameter to denote that you want the\n `labelInfo` returned within `includeLabels`.\n\nIf successful, the [response\nbody](/workspace/drive/api/reference/rest/v3/files/list#response-body) contains the list\nof files. \n\n### Java\n\n List\u003cFile\u003e fileList = driveService.files().list().setIncludeLabels(\"\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e\").setFields(\"items(labelInfo, id)\").setQ(\"'labels/\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e' in labels and 'labels/\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e' in labels\").execute().getItems();\n\n### Python\n\n file_list = drive_service.files().list(includeLabels=\"\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e\", q=\"'labels/\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e' in labels and 'labels/\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e' in labels\", fields=\"items(labelInfo, id)\").execute();\n\n### Node.js\n\n /**\n * Search for Drive files with specific labels\n * @return{obj} file list with labelInfo\n **/\n async function searchForFileWithLabels() {\n // Get credentials and build service\n // TODO (developer) - Use appropriate auth mechanism for your app\n\n const {GoogleAuth} = require('google-auth-library');\n const {google} = require('googleapis');\n\n const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});\n const service = google.drive({version: 'v3', auth});\n try {\n const fileList = await service.files.list({\n includeLabels: '\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e',\n q: '\\'labels/\u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e\\' in labels and \\'labels/\u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e\\' in labels',\n fields:'files(labelInfo, id)',\n });\n return file;\n } catch (err) {\n // TODO (developer) - Handle error\n throw err;\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eLABEL_1_ID\u003c/var\u003e: The first `labelId` of a label to return.\n- \u003cvar translate=\"no\"\u003eLABEL_2_ID\u003c/var\u003e: The second `labelId` of a label to return."]]