US-20260127139-A1 - FILE QUERY METHOD AND APPARATUS, COMPUTER DEVICE, AND COMMUNICATION SYSTEM
Abstract
A file query method and apparatus, a computer device, and a communication system are disclosed, and relate to the computer field. The method includes: obtaining a file attribute of a target directory by sending a file query request that indicates to query the file attribute of the target directory, where the file attribute of the target directory indicates a file organization structure attribute of the target directory, and the file attribute of the target directory may include file attributes of a plurality of files in the target directory.
Inventors
- Mingqian Zhang
- Jing Yang
Assignees
- HUAWEI TECHNOLOGIES CO., LTD.
Dates
- Publication Date
- 20260507
- Application Date
- 20251231
- Priority Date
- 20230704
Claims (20)
- 1 . A method, comprising: receiving a file query request, wherein the file query request indicates to query a file attribute of a target directory, and the file attribute of the target directory indicates a file organization structure attribute of the target directory; obtaining the file attribute of the target directory based on the file query request; and sending the file attribute of the target directory.
- 2 . The method according to claim 1 , wherein the file query request comprises an attribute parameter of at least one of a directory, a file, or a folder.
- 3 . The method according to claim 2 , wherein the attribute parameter comprises at least one of a size, occupied space, a quantity, or a file type of the at least one of the directory, the file, or the folder.
- 4 . The method according to claim 3 , wherein the file attribute of the target directory comprises at least one of an attribute of the target directory, a file attribute of a file comprised in the target directory, or a folder attribute of a folder comprised in the target directory.
- 5 . The method according to claim 1 , wherein the target directory comprises a root directory or a subdirectory at any level that is comprised in the root directory.
- 6 . The method according to claim 1 , wherein the file query request further comprises a check value, and the check value comprises at least one of a client identifier or a restart verification identifier.
- 7 . The method according to claim 1 , wherein a format of the file query request is set based on a file access protocol, and the file access protocol comprises any one of a server message block (SMB) protocol, a network file system (NFS) protocol, or a network attached storage (NAS) protocol.
- 8 . The method according to claim 1 , wherein sending the file query request comprises: sending the file query request in a synchronous manner.
- 9 . The method according to claim 1 , wherein sending the file query request comprises: sending the file query request in an asynchronous manner.
- 10 . A computer device, comprising: memory and one or more processors, wherein the memory stores a set of computer instructions, that when executed by the one or more processors, cause the computer device to: receive a file query request, wherein the file query request indicates to query a file attribute of a target directory, and the file attribute of the target directory indicates a file organization structure attribute of the target directory; obtain the file attribute of the target directory based on the file query request; and send the file attribute of the target directory.
- 11 . The computer device according to claim 10 , wherein the file query request comprises an attribute parameter of at least one of a directory, a file, or a folder.
- 12 . The computer device according to claim 11 , wherein the attribute parameter comprises at least one of a size, occupied space, a quantity, or a file type of the at least one of the directory, the file, or the folder.
- 13 . The computer device according to claim 12 , wherein the file attribute of the target directory comprises at least one of an attribute of the target directory, a file attribute of a file comprised in the target directory, or a folder attribute of a folder comprised in the target directory.
- 14 . The computer device according to claim 10 , wherein the target directory comprises a root directory or a subdirectory at any level that is comprised in the root directory.
- 15 . The computer device according to claim 10 , wherein the file query request further comprises a check value, and the check value comprises at least one of a client identifier or a restart verification identifier.
- 16 . The computer device according to claim 10 , wherein a format of the file query request is set based on a file access protocol, and the file access protocol comprises any one of a server message block (SMB) protocol, a network file system (NFS) protocol, or a network attached storage (NAS) protocol.
- 17 . The computer device according to claim 10 , wherein sending the file query request comprises: sending the file query request in a synchronous manner.
- 18 . The computer device according to claim 10 , wherein sending the file query request comprises: sending the file query request in an asynchronous manner.
- 19 . A communication system, comprising: a client, configured to: send a file query request, wherein the file query request indicates to query a file attribute of a target directory, and the file attribute of the target directory indicates a file organization structure attribute of the target directory; and receive the file attribute of the target directory; and a computer device configured to: receive a file query request, wherein the file query request indicates to query a file attribute of a target directory, and the file attribute of the target directory indicates a file organization structure attribute of the target directory; obtain the file attribute of the target directory based on the file query request; and send the file attribute of the target directory.
- 20 . The communication system according to claim 19 , wherein the file query request comprises an attribute parameter of at least one of a directory, a file, or a folder.
Description
CROSS-REFERENCE TO RELATED APPLICATIONS This application is a continuation of International Application No. PCT/CN2024/070614, filed on Jan. 4, 2024, which claims priority to Chinese Patent Application No. 202310815614.4, filed on Jul. 4, 2023. The disclosures of the aforementioned applications are hereby incorporated by reference in their entireties. TECHNICAL FIELD This application relates to the computer field, and in particular, to a file query method and apparatus, a computer device, and a communication system. BACKGROUND Currently, a client may mount a shared file of a server based on a network file system, and remotely access the shared file of the server through a network. For example, the client queries an attribute of a file (for example, a location and a size of the file) in the server. Generally, the client first obtains a file list from the server, and then queries attributes of files in the file list. A larger quantity of files indicates a larger quantity of query requests that need to be sent by the client, resulting in low file query efficiency and high network bandwidth overheads. SUMMARY This application provides a file query method and apparatus, a computer device, and a communication system, to resolve problems of low file query efficiency and high network bandwidth overheads. According to a first aspect, this application provides a file query method. The method includes: obtaining a file attribute of a target directory by sending a file query request that indicates to query the file attribute of the target directory, where the file attribute of the target directory indicates a file organization structure attribute of the target directory. A file organization structure may include a plurality of levels of directories, for example, a subdirectory, a first-level subdirectory, and a second-level subdirectory. A directory at each level may include a plurality of files or folders. The file attribute of the target directory may include file attributes of a plurality of files in the target directory. Compared with a case in which a client needs to send a file query request for each file, according to the file query method provided in this application, the client sends a file query request once, where the request indicates to query the file attributes of the plurality of files in the target directory, and receives attribute results of the plurality of files in the target directory, to improve file query efficiency. The query request and the attribute results are transmitted only once in a network, to reduce network bandwidth overheads. In addition, compared with a case in which the client caches a file attribute of a file, and collects statistics on file attributes of a plurality of files, according to the file query method provided in this application, the client may receive a statistics collection result of the file attributes of the plurality of files without caching the file attributes of the files and collecting statistics on and summarizing the file attributes of the files, to reduce consumption of memory resources and computing resources. According to a second aspect, this application provides a file query method. The method includes: receiving a file query request that indicates to query a file attribute of a target directory, where the file attribute of the target directory indicates a file organization structure attribute of the target directory; obtaining a file attribute of the target directory based on the received file query request; and sending the obtained file attribute of the target directory. After receiving the file query request sent by a client, a server may collectively summarize attributes such as a size of the target directory, occupied space, a total quantity of included files, and a total quantity of included folders. Optionally, the server queries attributes such as sizes and occupied space of folders included in the target directory, or attributes such as sizes and occupied space of files included in the target directory. Optionally, the server collectively summarizes attributes such as a quantity, sizes, and occupied space of folders included in the target directory, or attributes such as a quantity, sizes, and occupied space of files included in the target directory. Instead of performing a file attribute query operation on each file in the target directory, the client sends a file query request once to control the server to perform file attribute query operations on a plurality of files, to improve file query efficiency. In a possible implementation, the file query request includes an attribute parameter of at least one of a directory, a file, or a folder. In another possible implementation, an attribute parameter includes at least one of a size, occupied space, a quantity, or a file type. The file query request may meet different query granularities. The file query request includes different query granularities, and attribute parameters of query granularities at