File storage method and device

By using a multi-level directory structure file storage scheme, the target number of levels is calculated based on the number of files and rules, and the target directory structure is created. This solves the problem of low access efficiency caused by the increase in the number of folders and achieves more efficient file access.

CN115617762BActive Publication Date: 2026-07-07HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
Filing Date
2022-09-21
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

The existing file system suffers from low access efficiency as the number of folders increases linearly during file storage.

Method used

A multi-level directory structure is adopted. The target level is calculated based on the number of files and the directory hierarchy rules. A target directory structure that conforms to the directory hierarchy rules is created, and the files are stored under the bottom-level directory entries, and the unique identifier and path of the stored files are associated.

Benefits of technology

By reducing the number of directory entries at the same level, file access efficiency can be improved, avoiding the decline in access efficiency caused by an unlimited increase in the number of folders.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115617762B_ABST
    Figure CN115617762B_ABST
Patent Text Reader

Abstract

The application discloses a file storage method and device, and the method comprises the following steps: acquiring the file quantity of a to-be-stored file and a directory layering rule, the directory layering rule comprising the upper limit of the directory item quantity of each level directory and the upper limit of the file quantity of a bottom directory item; calculating a target layer number, the upper limit of the file storage quantity of a full directory structure with the layer number being the target layer number and meeting the directory layering rule, and being greater than the upper limit of the file storage quantity of a full directory structure with the layer number being the target layer number minus one and meeting the directory layering rule; creating a target directory structure with the layer number being the target layer number and meeting the directory layering rule, storing the to-be-stored file under the bottom directory item of the target directory structure, and associating and storing the unique identification of each to-be-stored file with the storage path. The application provides a file storage scheme based on a multi-layer directory structure, and improves the access efficiency of the stored file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of file system technology, and in particular to a file storage method and device. Background Technology

[0002] Currently, file systems store files sequentially into their corresponding folders, creating new folders only when a folder reaches a certain number of files. This method, which stores all files under the same level of folders, causes the number of folders at that level to increase linearly, resulting in low access efficiency when accessing files. Summary of the Invention

[0003] The main objective of this invention is to provide a file storage method and device, aiming to propose a file storage scheme based on a multi-level directory structure to improve the access efficiency of stored files.

[0004] To achieve the above objectives, the present invention provides a file storage method, the method comprising the following steps:

[0005] The number of files to be stored is obtained, and the directory hierarchy rules are obtained. The directory hierarchy rules include the upper limit of the number of directory entries corresponding to each level of directory and the upper limit of the number of first files to be stored corresponding to each bottom-level directory entry. The bottom-level directory entry is the directory entry under the lowest level directory in each level of directory.

[0006] The target number of layers is calculated based on the number of files and the directory hierarchy rules, wherein the number of files is less than or equal to the second file storage limit and greater than the third file storage limit, the second file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers and conforming to the directory hierarchy rules, and the third file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers minus one and conforming to the directory hierarchy rules.

[0007] Create a target directory structure with the target number of layers and conforming to the directory hierarchy rules, store the files to be stored in the bottom directory entries of the target directory structure, and associate the unique identifier of each file to be stored with the storage path in the target directory structure.

[0008] Optionally, the file storage method is applied to a file storage system, and before the step of obtaining the number of files to be stored, it further includes:

[0009] When the file storage system receives a file for the first time after its initial startup, the received file will be used as the file to be stored; or,

[0010] Whenever the file storage system receives a file, it uses the files already stored in the file storage system and the received file as the file to be stored; or,

[0011] Whenever the file storage system receives a file, it uses the received file as the file to be stored.

[0012] Optionally, the step of creating a target directory structure with the target number of layers and conforming to the directory hierarchy rules, and storing the file to be stored in the bottom directory entry of the target directory structure, includes:

[0013] Create a target directory structure with the target number of layers, conforming to the directory hierarchy rules, and having a maximum file storage limit equal to the number of files, and store the files to be stored in the bottom directory entry of the target directory structure.

[0014] Optionally, after the step of associating and storing the unique identifier of each of the files to be stored with the storage path in the target directory structure, the method further includes:

[0015] When a new file is added to the target directory structure, it is detected whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the number of new directory layers. The threshold for triggering the number of new directory layers is determined based on the fourth file storage limit. The fourth file storage limit is the file storage limit of a full directory structure with the current directory layer number of the target directory structure and that conforms to the directory layering rules.

[0016] If the value is greater than the target directory, a new subdirectory entry is created for the current bottom-level directory entry of the target directory structure according to the directory hierarchy rules, and the files stored under the current bottom-level directory entry are moved to the newly created subdirectory entry. The storage path associated with the unique identifier of the moved file is updated.

[0017] Optionally, before the step of detecting whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the addition of new directory levels, the method further includes:

[0018] When a new file is added to the target directory structure, the upper limit of the storage quantity of the fourth file is calculated;

[0019] The upper limit of the number of fourth files stored is multiplied by the first preset percentage to obtain the threshold for triggering the number of new directory layers.

[0020] Optionally, the step of creating a new subdirectory entry for the current underlying directory entry of the target directory structure according to the directory hierarchy rules, and transferring the files stored under the current underlying directory entry to the newly created subdirectory entry includes:

[0021] According to the directory hierarchy rules, a target number of subdirectory entries are created for the current bottom-level directory entries of the target directory structure. The number of files currently stored in the target directory structure is less than or equal to the upper limit of the number of files stored in the subdirectory entries of the target number, and is greater than the upper limit of the number of files stored in the subdirectory entries of the target number minus one number.

[0022] Move the files stored in the current underlying directory to the newly created subdirectory.

[0023] Optionally, after the step of associating and storing the unique identifier of each of the files to be stored with the storage path in the target directory structure, the method further includes:

[0024] After deleting a file in the target directory structure, it is detected whether the number of files currently stored in the target directory structure is less than the threshold for reducing the number of directory levels. The threshold for reducing the number of directory levels is determined based on the fifth file storage limit. The fifth file storage limit is the file storage limit of a full directory structure with a number of levels equal to the current number of directory levels in the target directory structure minus one level, and which conforms to the directory layering rules. The current number of directory levels is greater than 1.

[0025] If the value is less than the target directory structure, the files stored in the current bottom-level directory entry of the target directory structure are moved to the second-to-last directory entry of the target directory structure. After the transfer, empty directory entries without stored files in the target directory structure are deleted, and the storage path associated with the unique identifier of the transferred file is updated.

[0026] Optionally, the step of transferring files stored under the current bottom-level directory entry of the target directory structure to the second-to-last directory entry of the target directory structure includes:

[0027] Files stored under the current bottom-level directory entry of the target directory structure are moved to the second-to-last directory entry of the target directory structure according to the transfer rules, wherein the transfer rules include starting to store files under another directory entry only after the current directory entry is full.

[0028] Optionally, after the step of associating and storing the unique identifier of each of the files to be stored with the storage path in the target directory structure, the method further includes:

[0029] When a triggering event is detected that requires adjustment of the directory hierarchy of the target directory structure, the system checks whether it is in a preset idle state.

[0030] If the target directory structure is in a preset idle state, the number of directory levels is adjusted according to the triggering event.

[0031] If the system is not in a preset idle state, then the number of directory layers in the target directory structure is adjusted according to the triggering event using the second preset percentage of the total system resources.

[0032] Optionally, after the step of associating and storing the unique identifier of each of the files to be stored with the storage path in the target directory structure, the method further includes:

[0033] Determine the target historical files whose last access time was before a preset time from each file stored in the target directory structure;

[0034] Each of the target historical files is extracted from the target directory structure and compressed into a single compressed file;

[0035] The compressed file is stored as a new file in the underlying directory of the target directory structure.

[0036] To achieve the above objectives, the present invention also provides a file storage device, the file storage device comprising: a memory, a processor, and a file storage program stored on the memory and executable on the processor, wherein the file storage program, when executed by the processor, implements the steps of the file storage method described above.

[0037] Furthermore, to achieve the above objectives, the present invention also proposes a computer-readable storage medium storing a file storage program, which, when executed by a processor, implements the steps of the file storage method described above.

[0038] In this embodiment of the invention, the target number of levels is determined based on the number of files to be stored and directory hierarchy rules. A target directory structure conforming to the directory hierarchy rules is constructed for the target number of levels. The files to be stored are stored under the bottom-level directory entries of the target directory structure, and the unique identifier of each file to be stored is associated with its storage path in the target directory structure. This achieves a file storage scheme based on a multi-level directory structure. Compared to storing all files under folders at the same level, where a large number of folders leads to low file access efficiency, the file storage scheme based on a multi-level directory structure in this embodiment of the invention significantly reduces the number of directory entries at the same level, thereby improving the access efficiency of the stored files. Furthermore, some file systems have an upper limit on the number of subdirectory entries. When all files are stored under folders at the same level, the number of folders may reach the limit, leading to an unlimited increase in the number of files in the same folder, which in turn reduces file access efficiency. However, the file storage scheme based on a multi-level directory structure in this embodiment can vertically expand directory entries according to directory hierarchy rules, and there is no upper limit to the number of directory entries that can be created. This prevents the number of files under the same directory entry from increasing indefinitely, thereby improving file access efficiency. Attached Figure Description

[0039] Figure 1 This is a schematic diagram of the hardware operating environment involved in the embodiments of the present invention;

[0040] Figure 2 This is a flowchart illustrating the first embodiment of the file storage method of the present invention;

[0041] Figure 3 This is a schematic diagram of a multi-level directory structure according to an embodiment of the present invention.

[0042] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0043] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0044] like Figure 1 As shown, Figure 1 This is a schematic diagram of the device structure of the hardware operating environment involved in the embodiments of the present invention.

[0045] It should be noted that the file storage device in the embodiments of the present invention can be a smartphone, a personal computer, a server, or other devices, and no specific limitations are imposed here.

[0046] like Figure 1 As shown, the file storage device may include: a processor 1001, such as a CPU; a network interface 1004; a user interface 1003; a memory 1005; and a communication bus 1002. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be high-speed RAM or non-volatile memory, such as a disk drive. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0047] Those skilled in the art will understand that Figure 1 The device structure shown does not constitute a limitation on the file storage device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0048] like Figure 1As shown, the memory 1005, as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a file storage program. The operating system is a program that manages and controls the device's hardware and software resources, supporting the operation of the file storage program and other software or programs. Figure 1 In the device shown, the user interface 1003 is mainly used for data communication with the client; the network interface 1004 is mainly used for establishing a communication connection with the server; and the processor 1001 can be used to call the file storage program stored in the memory 1005 and perform the following operations:

[0049] The number of files to be stored is obtained, and the directory hierarchy rules are obtained. The directory hierarchy rules include the upper limit of the number of directory entries corresponding to each level of directory and the upper limit of the number of first files to be stored corresponding to each bottom-level directory entry. The bottom-level directory entry is the directory entry under the lowest level directory in each level of directory.

[0050] The target number of layers is calculated based on the number of files and the directory hierarchy rules, wherein the number of files is less than or equal to the second file storage limit and greater than the third file storage limit, the second file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers and conforming to the directory hierarchy rules, and the third file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers minus one and conforming to the directory hierarchy rules.

[0051] Create a target directory structure with the target number of layers and conforming to the directory hierarchy rules, store the files to be stored in the bottom directory entries of the target directory structure, and associate the unique identifier of each file to be stored with the storage path in the target directory structure.

[0052] Furthermore, prior to the step of obtaining the number of files to be stored, the processor 1001 may also call the file storage program stored in the memory 1005 to perform the following operations:

[0053] When the file storage system receives a file for the first time after its initial startup, that received file will be used as the file to be stored; or,

[0054] Whenever the file storage system receives a file, it uses the files already stored in the file storage system and the received file as the file to be stored; or,

[0055] Whenever the file storage system receives a file, it uses the received file as the file to be stored.

[0056] Furthermore, the operation of creating a target directory structure with the target number of layers and conforming to the directory hierarchy rules, and storing the file to be stored in the bottom directory entry of the target directory structure includes:

[0057] Create a target directory structure with the target number of layers, conforming to the directory hierarchy rules, and having a maximum file storage limit equal to the number of files, and store the files to be stored in the bottom directory entry of the target directory structure.

[0058] Furthermore, after associating the unique identifier of each file to be stored with its storage path in the target directory structure, the processor 1001 can also call the file storage program stored in the memory 1005 to perform the following operations:

[0059] When a new file is added to the target directory structure, it is detected whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the number of new directory layers. The threshold for triggering the number of new directory layers is determined based on the fourth file storage limit. The fourth file storage limit is the file storage limit of a full directory structure with the current directory layer number of the target directory structure and that conforms to the directory layering rules.

[0060] If the value is greater than the target directory, a new subdirectory entry is created for the current bottom-level directory entry of the target directory structure according to the directory hierarchy rules, and the files stored under the current bottom-level directory entry are moved to the newly created subdirectory entry. The storage path associated with the unique identifier of the moved file is updated.

[0061] Furthermore, before the operation of detecting whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the addition of new directory levels, the processor 1001 can also call the file storage program stored in the memory 1005 to perform the following operations:

[0062] When a new file is added to the target directory structure, the upper limit of the storage quantity of the fourth file is calculated;

[0063] The upper limit of the number of fourth files stored is multiplied by the first preset percentage to obtain the threshold for triggering the number of new directory layers.

[0064] Furthermore, the operation of creating a new subdirectory entry for the current underlying directory entry of the target directory structure according to the directory hierarchy rules, and transferring the files stored under the current underlying directory entry to the newly created subdirectory entry includes:

[0065] According to the directory hierarchy rules, a target number of subdirectory entries are created for the current bottom-level directory entries of the target directory structure. The number of files currently stored in the target directory structure is less than or equal to the upper limit of the number of files stored in the subdirectory entries of the target number, and is greater than the upper limit of the number of files stored in the subdirectory entries of the target number minus one number.

[0066] Move the files stored in the current underlying directory to the newly created subdirectory.

[0067] Furthermore, after associating the unique identifier of each file to be stored with its storage path in the target directory structure, the processor 1001 can also call the file storage program stored in the memory 1005 to perform the following operations:

[0068] After deleting a file in the target directory structure, it is detected whether the number of files currently stored in the target directory structure is less than the threshold for reducing the number of directory levels. The threshold for reducing the number of directory levels is determined based on the fifth file storage limit. The fifth file storage limit is the file storage limit of a full directory structure with a number of levels equal to the current number of directory levels in the target directory structure minus one level, and which conforms to the directory layering rules. The current number of directory levels is greater than 1.

[0069] If the value is less than the target directory structure, the files stored in the current bottom-level directory entry of the target directory structure are moved to the second-to-last directory entry of the target directory structure. After the transfer, empty directory entries without stored files in the target directory structure are deleted, and the storage path associated with the unique identifier of the transferred file is updated.

[0070] Furthermore, the operation of transferring files stored under the current bottom-level directory entry of the target directory structure to the second-to-last directory entry of the target directory structure includes:

[0071] Files stored under the current bottom-level directory entry of the target directory structure are sequentially transferred to the second-to-last directory entry of the target directory structure according to the transfer rules, wherein the transfer rules include starting to store files under another directory entry only after the current directory entry is full.

[0072] Furthermore, after associating the unique identifier of each file to be stored with its storage path in the target directory structure, the processor 1001 can also call the file storage program stored in the memory 1005 to perform the following operations:

[0073] When a triggering event is detected that requires adjustment of the directory hierarchy of the target directory structure, the system checks whether it is in a preset idle state.

[0074] If the target directory structure is in a preset idle state, the number of directory levels is adjusted according to the triggering event.

[0075] If the system is not in a preset idle state, then the number of directory layers in the target directory structure is adjusted according to the triggering event using the second preset percentage of the total system resources.

[0076] Furthermore, after associating the unique identifier of each file to be stored with its storage path in the target directory structure, the processor 1001 can also call the file storage program stored in the memory 1005 to perform the following operations:

[0077] Determine the target historical files whose last access time was before a preset time from each file stored in the target directory structure;

[0078] Each of the target historical files is extracted from the target directory structure and compressed into a single compressed file;

[0079] The compressed file is stored as a new file in the underlying directory of the target directory structure.

[0080] Based on the above structure, various embodiments of the file storage method are proposed.

[0081] Reference Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the file storage method of the present invention.

[0082] This invention provides an embodiment of a file storage method. It should be noted that although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order. In this embodiment, the executing entity of the file storage method can be a smartphone, personal computer, server, or other device; no limitation is imposed in this embodiment. The executing entity is omitted from the description in this embodiment. In this embodiment, the file storage method includes the following steps:

[0083] Step S10: Obtain the number of files to be stored and obtain the directory hierarchy rules, wherein the directory hierarchy rules include the upper limit of the number of directory entries corresponding to each level of directory and the upper limit of the number of first files to be stored corresponding to each bottom-level directory entry, and the bottom-level directory entry is the directory entry under the lowest level directory in each level of directory.

[0084] To address the problem of low file access efficiency when the number of files is large, which is caused by storing files in folders at the same level in current file storage systems, this paper proposes storing files in a multi-level directory structure to improve access efficiency when accessing the stored files.

[0085] A directory structure is a directory structure that includes at least one level. Each level of directory includes at least one directory entry. The lowest-level directory entry is used to store files. Directory entries at other levels besides the lowest-level entry are called parent directory entries. Parent directory entries do not store files but instead store subdirectory entries, which are the next level down from the parent directory entry. For example, when the directory structure has one level, it includes one level of directories, which includes at least one directory entry used to store files; that is, this directory entry belongs to the lowest level. When the directory structure has two levels, it includes two levels of directories. The first level includes at least one directory entry (belonging to the parent directory entry), and the second level includes at least one subdirectory entry from the at least one directory entry in the first level directory. This subdirectory entry is used to store files; that is, this subdirectory entry belongs to the lowest level. And so on. Figure 3 The diagram illustrates a two-level directory structure. 1.1 and 1.1024 are two directory entries within the first-level directory (the ellipsis indicates other directory entries within the first-level directory are omitted). Each directory entry within the first-level directory belongs to the parent directory level, storing subdirectories, which are the directory entries within the second-level directory. For example, the directory entry 1.1 stores directory entries 2.1-1, 2.1-2, ..., 2.1-1024, which are part of the second-level directory. The subdirectories within the directory entry 1.1024 are not shown in the diagram, but it can be understood that they also belong to the second-level directory. Each directory entry within the second-level directory is the lowest-level directory, storing files. For example, the diagram shows files 1, 2, 3, ..., 1024 stored under the directory entry 2.1-2 in the second-level directory, and also shows the files stored within the second-level directory.

[0086] Files to be stored are files that need to be stored by creating a new directory structure. In specific application scenarios, trigger conditions can be set as needed so that the corresponding file is used as the file to be stored when the trigger conditions are met. For example, when the file storage method execution subject in this embodiment is a file storage system, in one implementation, the received file can be triggered as a file to be stored when the file storage system receives a file for the first time after its initial startup. That is, a directory structure is created to store the received file only when it receives a file for the first time after its initial startup. Subsequent files received by the file storage system will not be stored by creating a new directory structure, but can be stored in other ways or as new files in the already created directory structure. In another implementation, both the files already stored in the file storage system and the received file can be triggered as files to be stored whenever the file storage system receives a file. That is, each time a file is received, both the files already stored in the file storage system and the received file are stored by creating a new directory structure, and the previously created directory structure can be deleted. In yet another implementation, the received file can also be treated as a file to be stored whenever the file storage system receives a file. That is, the file storage system creates a new directory structure to store each new file it receives.

[0087] In this embodiment, for the files to be stored, a directory structure with a corresponding number of levels can be created to store the files. To determine the required number of levels in the directory structure, the number of files to be stored and the directory hierarchy rules can be obtained. The directory hierarchy rules include the upper limit on the number of directory entries corresponding to each level of directory and the upper limit on the number of files to be stored corresponding to each bottom-level directory entry (hereinafter referred to as the first file storage limit for distinction). The upper limit on the number of directory entries corresponding to each level of directory is the upper limit on the number of directory entries that can be created at each level of directory, and the upper limit on the number of files to be stored corresponding to each bottom-level directory entry is the upper limit on the number of files that can be stored under the bottom-level directory entry.

[0088] Depending on the specific application scenario, the number of files to be stored may be 1 or a number greater than 1.

[0089] Understandably, after obtaining the directory hierarchy rules, the maximum number of files that can be stored in a directory structure of any number of levels can be calculated. For example, if the directory hierarchy rules stipulate that the maximum number of directory entries in the P-th level directory is 1024 to the power of P (that is, the first-level directory can create 1024 directory entries, and the subdirectory entries that can be created under the directory entries in all other non-bottom-level directories are 1024), and the maximum number of files that can be stored in the first level directory entry is 1024, then the number of bottom-level directory entries in a two-level full directory structure constructed according to these rules is 1024*1024, and the total number of files that can be stored is 1024*1024*1024. It should be explained that a full directory structure is a directory structure in which the number of directory entries in each level of the directory structure reaches the upper limit of the number of directory entries specified in the directory hierarchy rules. In contrast, if the number of directory entries in at least one level of a directory structure does not reach the upper limit of the number of directory entries in that level of the directory as specified in the directory hierarchy rules, then the directory structure cannot be called a full directory structure.

[0090] It should be noted that the maximum number of subdirectory entries that can be created under the directory entries of each level of the directory hierarchy rules (i.e., the upper limit of the number of subdirectory entries) can be the same or different. The upper limit of the number of first files stored in each bottom-level directory entry can be the same or different, and no restrictions are imposed in this embodiment.

[0091] Step S20: Calculate the target number of layers based on the number of files and the directory hierarchy rules, wherein the number of files is less than or equal to the second file storage limit and greater than the third file storage limit, the second file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers and conforming to the directory hierarchy rules, and the third file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers minus one and conforming to the directory hierarchy rules.

[0092] Based on the number of files to be stored and the directory hierarchy rules, a target number of levels can be calculated. This target number of levels ensures that the number of files to be stored is less than or equal to the second maximum file storage limit and greater than the third maximum file storage limit. The second maximum file storage limit is the maximum number of files that can be stored in a full directory structure with the target number of levels and conforming to the directory hierarchy rules. The third maximum file storage limit is the maximum number of files that can be stored in a full directory structure with the directory level one level lower than the target number of levels and conforming to the directory hierarchy rules. In other words, if a full directory structure with level P-1 conforming to the directory hierarchy rules cannot store the files to be stored, but a full directory structure with level P conforming to the directory hierarchy rules can just store the files to be stored or has extra storage space after storing the files to be stored, then a directory structure with level P can be created to store the files to be stored. This ensures that all files to be stored are stored while avoiding the creation of too many directory entries that would consume excessive storage space.

[0093] It should be noted that a directory structure that conforms to the directory hierarchy rules means that the number of directory entries under each level of the target structure does not exceed the upper limit of the number of directory entries for the corresponding level of the directory as specified in the directory hierarchy rules, and the number of files stored in the bottom directory entries of the directory structure does not exceed the upper limit of the first file storage quantity of the bottom directory entries as specified in the directory hierarchy rules.

[0094] In this embodiment, the method for calculating the target number of levels based on the number of files to be stored and the directory hierarchy rules is not limited. For example, the total number of files that can be stored in a full directory structure conforming to the directory hierarchy rules at various levels can be calculated in advance, and then compared with the number of files to be stored to determine the target number of levels. As another example, when the number of files to be stored is N (N>0 and is a positive integer), the directory hierarchy rules specify that the upper limit of the number of directory entries in the i-th level directory is x. n The number of second files stored in each underlying directory entry is x raised to the power of i. n At this time, you can first follow x m =N to calculate m, then divide m by n and round up to get the target layer number P.

[0095] Step S30: Create a target directory structure with the target number of layers and conforming to the directory hierarchy rules, store the files to be stored in the bottom directory of the target directory structure, and associate the unique identifier of each file to be stored with the storage path in the target directory structure.

[0096] After determining the target number of levels, a directory structure with the target number of levels and conforming to directory hierarchy rules can be created (hereinafter referred to as the target directory structure for distinction). The files to be stored are then stored under the bottom-level directory entries of this target directory structure. It should be noted that the target directory structure can be a full directory structure or a partial directory structure; this is not limited in this embodiment. The files to be stored can be stored at the same time as the target directory structure is created, or they can be stored after the target directory structure is created; this is not limited in this embodiment.

[0097] Each file has a pre-arranged unique identifier. After the file to be stored is stored in the target directory structure, its unique identifier is associated with its storage path in the target directory structure. The storage location for associating the unique identifier with the storage path is not limited in this embodiment; for example, it can be stored in a separate path table.

[0098] The unique identifier of the file to be accessed can be used to find the storage path associated with it, and then the file can be searched for and accessed in the target directory structure according to the storage path.

[0099] It is understandable that in this embodiment, the target number of levels is determined based on the number of files to be stored and the directory hierarchy rules. A target directory structure conforming to the directory hierarchy rules is constructed for the target number of levels. The files to be stored are stored under the bottom-level directory entries of the target directory structure, and the unique identifier of the files to be stored is associated with the storage path in the target directory structure. This achieves a file storage scheme based on a multi-level directory structure. Compared to storing all files under folders at the same level, where a large number of folders leads to low file access efficiency, the file storage scheme based on a multi-level directory structure in this embodiment greatly reduces the number of directory entries at the same level, thereby improving the access efficiency of the stored files. Furthermore, some file systems have an upper limit on the number of subdirectory entries. When all files are stored under folders at the same level, the number of folders may reach the upper limit, leading to an unlimited increase in the number of files in the same folder, which in turn reduces file access efficiency. However, the file storage scheme based on a multi-level directory structure in this embodiment can vertically expand directory entries according to the directory hierarchy rules, and there is no upper limit to the number of directory entries that can be created. This prevents the number of files under the same directory entry from increasing indefinitely, thereby improving file access efficiency.

[0100] Furthermore, in one embodiment, after constructing the target directory structure and storing the files to be stored in the target directory structure, when a new file that needs to be stored in the target directory structure is detected, the new file can be stored under a low-level directory entry that is not full of files if such a low-level directory entry exists in the target directory structure; if there is no low-level directory entry that is not full of files, but there is a directory entry that is not full of subdirectories, a new subdirectory entry is created for that directory entry, and the new file is stored under the newly created low-level directory entry; if there is no low-level directory entry that is not full of files and no directory entry that is not full of subdirectories in the target directory structure, the number of directory levels in the target directory structure can be increased. Specifically, this can be done by creating new subdirectory entries for the low-level directory entries in the target directory structure, and then transferring the files stored in each low-level directory entry to the newly created subdirectory entry, so that the newly created subdirectory entry becomes a new low-level directory entry, thereby increasing the number of directory levels.

[0101] It should be noted that after the target directory structure is created, any subsequent additions or deletions of files, levels, or directory items are considered adjustments to the target directory structure, not the creation of a new directory structure. In other words, after adding or removing files, the target directory structure is still referred to as the target directory structure.

[0102] Further, in one embodiment, step S30, which involves creating a target directory structure with the target number of layers and conforming to the directory hierarchy rules, and storing the file to be stored under the bottom directory entry of the target directory structure, includes:

[0103] Step S301: Create a target directory structure with the target number of layers, conforming to the directory layering rules, and with the upper limit of the number of files to be stored equal to the number of files, and store the files to be stored in the bottom directory entry of the target directory structure.

[0104] In this embodiment, to avoid wasting storage space by creating empty directory entries when building the directory structure, a target directory structure that can store exactly the number of files to be stored can be created based on the number of files to be stored. In a specific embodiment, the target directory structure can be created first and then the files to be stored can be stored, or the files can be created and stored at the same time.

[0105] For example, in one embodiment, the number of target directory entries to be created at each level and the number of target files to be stored in a directory structure with a target number of levels, conforming to the directory hierarchical rules, and whose file storage limit is equal to the number of files to be stored can be calculated according to the directory construction rules. The directory construction rules stipulate that at most one level has a number of directory entries that does not reach the maximum number of directory entries for that level as specified by the directory hierarchical rules, and at most one bottom-level directory entry has a number of files that does not reach the second maximum number of files to be stored as specified by the directory hierarchical rules. There are many specific methods for calculating the number of target directory entries and the number of target files, and no limitation is made here. The target directory structure is constructed based on the number of target directory entries and the number of target files, and then the files to be stored are stored in the target directory structure.

[0106] For example, in another implementation, the files to be stored can be stored sequentially according to storage rules. These rules stipulate that a new underlying directory entry is built only after a subdirectory entry of a non-underlying directory entry is fully stored, and subdirectory entries of other non-underlying directory entries at the same level as a non-underlying directory entry are built only after a subdirectory entry of a non-underlying directory entry is fully built. Assuming the number of files to be stored is 5, the maximum number of directory entries in the first-level directory is 2, the maximum number of directory entries in the second-level directory is 4, and the maximum number of second files stored in each underlying directory entry is 2, then the calculated target level is 2. First, the first directory entry 1.1 of the first-level directory is created. Then, the first subdirectory entry 2.1-1 of the 1.1 directory entry in the second-level directory is created, storing the first and second files under the 2.1-1 directory entry. Next, the second subdirectory entry 2.1-2 of the 1.1 directory entry is created, storing the third and fourth files under the 2.1-1 directory entry. The file is stored under the 2.1-2 directory entry; then, the second directory entry 1.2 is created in the first-level directory, and the first subdirectory entry 2.2-1 is created under the 1.2 directory entry in the second-level directory. The fifth file is stored under the 2.2-1 directory entry. At this point, there are only 3 directory entries in the second-level directory of the created directory structure, which has not yet reached the upper limit of 4 directory entries in the directory hierarchy rules. Therefore, there are no empty directory entries. When the number of files to be stored is large, the number of empty directory entries can be greatly reduced, thereby avoiding the waste of storage space.

[0107] Furthermore, in one embodiment, after step S30, the method further includes:

[0108] Step S40: Determine the target historical files whose last access time was before a preset time from each file stored in the target directory structure;

[0109] In this embodiment, the last access time of a file can be recorded each time it is accessed in the target directory structure. Periodically, or upon receiving a file compression command, files whose last access time is before a preset time (hereinafter referred to as target history files) are identified from the various files stored in the target directory structure. The preset time can be set in advance as needed; a file's last access time before this preset time indicates that the file has not been accessed for a long time.

[0110] Step S50: Extract each of the target historical files from the target directory structure and compress them into a single compressed file;

[0111] The target historical files are extracted from the target directory structure and compressed into a single compressed file. The compression method is not limited in this embodiment. It is understood that after extracting the target historical files from the target directory structure, the target directory structure will no longer contain the previously extracted target historical files.

[0112] Step S60: Store the compressed file as a new file in the underlying directory entry of the target directory structure.

[0113] Store the compressed file as a new file in the underlying directory of the target directory structure. Refer to the specific implementation method for storing new files described above.

[0114] Furthermore, in one embodiment, after the target historical files are packaged into a compressed file and stored, it is possible to check whether there are empty directory entries in the target directory structure. If there are empty directory entries, they can be deleted to reduce the storage space occupied.

[0115] Based on the first embodiment described above, a second embodiment of the file storage method of the present invention is proposed. In this embodiment, after step S30, the method further includes:

[0116] Step A10: After adding a new file to the target directory structure, detect whether the number of files currently stored in the target directory structure is greater than the new directory layer trigger threshold. The new directory layer trigger threshold is determined based on the fourth file storage quantity limit. The fourth file storage quantity limit is the file storage quantity limit of a full directory structure with the current directory layer of the target directory structure and that conforms to the directory layering rules.

[0117] In this embodiment, after adding a file to the target directory structure, the number of directory levels of the target directory structure can be dynamically increased according to the changes in the number of files. Without increasing the upper limit of the number of subdirectory entries of a single directory entry and the upper limit of the second file storage of a single bottom-level directory entry, the upper limit of the file storage of the target directory structure can be expanded to ensure file access efficiency.

[0118] Specifically, when a new file is added to the target directory structure, it can be detected whether the number of files currently stored in the target directory structure exceeds the threshold for triggering the addition of a new directory level. This threshold can be determined based on the fourth file storage limit, which is the maximum number of files that can be stored in a full directory structure that is the current directory level of the target directory structure and conforms to directory hierarchy rules. In a specific implementation, the threshold can be directly calculated using this fourth file storage limit; that is, when the target directory structure is already full and all bottom-level directory entries are full, a new directory level needs to be added to store more files. Alternatively, the threshold can be calculated using this fourth file storage limit, for example, by multiplying it by a percentage; that is, when the number of files stored in the target directory structure is about to reach the maximum number of files that can be stored in a full directory structure corresponding to the current directory level of the target directory structure, a new directory level is added to accommodate any further additions.

[0119] Step A20: If the value is greater than the target directory structure, a new subdirectory entry is created for the current bottom-level directory entry according to the directory hierarchy rules. The files stored under the current bottom-level directory entry are then moved to the newly created subdirectory entry, and the storage path associated with the unique identifier of the moved files is updated.

[0120] When the number of files currently stored in the target directory structure exceeds the threshold for triggering the addition of new directory levels, subdirectory entries can be created for the current bottom-level directory entry in the target directory structure according to the directory layering rules. That is, the number of subdirectory entries created for the current bottom-level directory entry should be within the number of directory entries that can be created in the next level directory of the current bottom-level directory entry as specified by the directory layering rules.

[0121] Files stored in the current underlying directory are moved to newly created subdirectory entries. In this embodiment, there is no limitation on which current underlying directory entry is used to create a subdirectory entry, nor on how many subdirectory entries are created, as long as the created subdirectory entries can store all the files stored in the current target directory structure. In some implementations, files can be moved according to certain rules to store all files with the fewest possible subdirectory entries, avoiding the creation of unnecessary directory entries that consume storage space.

[0122] After moving files stored in the current underlying directory to a newly created subdirectory, update the storage path associated with the unique identifier of the moved file so that the file can still be found in the target directory structure based on its unique identifier after the file is moved.

[0123] Understandably, after moving the files stored under the current underlying directory to the newly created subdirectory, the current underlying directory is no longer the underlying directory, but the second-to-last directory, and the newly created subdirectory becomes the underlying directory.

[0124] Furthermore, in one embodiment, before step A10, the method further includes:

[0125] Step A30: After adding a new file to the target directory structure, calculate the upper limit of the storage quantity of the fourth file;

[0126] Step A40: Multiply the upper limit of the fourth file storage quantity by the first preset ratio to obtain the threshold for triggering the number of new directory layers.

[0127] When a new file is added to the target directory structure, the maximum number of files that can be stored in a full directory structure that meets the current directory hierarchy rules can be calculated; this is the fourth maximum file storage limit. The calculation method is not detailed here. Multiplying this fourth maximum file storage limit by a first preset percentage yields a threshold for triggering the addition of new directory levels. This first preset percentage can be set in advance as needed, for example, to 90%; or it can be dynamically adjusted. This first preset percentage is less than 1, so that when the number of files currently stored in the target directory structure exceeds the total number of target files multiplied by this first preset percentage, it indicates that the number of files stored in the target directory structure is about to reach the maximum file storage limit of a full directory structure corresponding to the current directory hierarchy. To avoid a decrease in file storage efficiency due to insufficient time to increase the directory hierarchy when a large number of new files arrive, the directory hierarchy is added in advance. It can be understood that the smaller the first preset percentage, the greater the likelihood of a decrease in file storage efficiency due to insufficient time to increase the directory hierarchy when a large number of new files arrive, and vice versa.

[0128] In a specific implementation, the first preset percentage can be dynamically adjusted based on the trend of the number of newly added files. For example, the first preset percentage can be initialized in advance; a recent preset time period is divided into a first time period and a second time period of equal duration, with the first time period being earlier than the second time period. The first number of newly added files in the first time period and the second number of newly added files in the second time period are counted. The second number is subtracted from the first number and then divided by the first number to obtain the growth rate of the number of newly added files. If the growth rate is greater than 0, the current first preset percentage is reduced according to the growth rate; if the growth rate is less than 0, the current first preset percentage is increased according to the absolute value of the growth rate.

[0129] Further, in one embodiment, step A20 includes:

[0130] Step A201: Create a target number of subdirectory entries for the current bottom-level directory entries of the target directory structure according to the directory hierarchical rules. The number of files currently stored in the target directory structure is less than or equal to the upper limit of the number of files stored in the subdirectory entries of the target number, and is greater than the upper limit of the number of files stored in the subdirectory entries of the target number minus one number.

[0131] In this embodiment, when it is necessary to increase the number of directory levels, a target number of subdirectory entries are created for the current bottom-level directory entries of the target directory structure according to the directory hierarchy rules. The target number is calculated based on the number of files currently stored in the target directory structure and the second maximum file storage capacity of the bottom-level directory entries as specified in the directory hierarchy rules. This ensures that the number of files currently stored in the target directory structure is less than or equal to the maximum file storage capacity of the target number of subdirectory entries, and greater than the maximum file storage capacity of the target number minus one number of subdirectory entries, thus avoiding the waste of storage space by creating empty directory entries. That is, assuming the target number is x, the number of files currently stored in the target directory structure is less than or equal to the maximum file storage capacity when x subdirectory entries are used as bottom-level directory entries, and greater than the maximum file storage capacity when x-1 subdirectory entries are used as bottom-level directory entries.

[0132] Step A202: Move the files stored in the current underlying directory to the newly created subdirectory.

[0133] Move the files stored in the current underlying directory to the newly created subdirectory. The specific method of moving the files is not limited here.

[0134] In one embodiment, subdirectory entries can be created sequentially for each underlying directory entry in the target directory structure. Furthermore, the creation of the next subdirectory entry only begins after one underlying directory entry is full of files, and the creation of subdirectory entries only begins after one underlying directory entry is full of subdirectory entries. This avoids creating redundant directory entries and wasting storage space. Further, in one embodiment, subdirectory entries can be created sequentially for each underlying directory entry in the target directory structure according to their creation time; that is, subdirectory entries can be created first for the underlying directory entries created earlier.

[0135] Furthermore, based on the first and / or second embodiments described above, a third embodiment of the file storage method of the present invention is proposed. In this embodiment, after step S30, the method further includes:

[0136] Step B10: After deleting a file in the target directory structure, detect whether the number of files currently stored in the target directory structure is less than the directory layer reduction trigger threshold. The directory layer reduction trigger threshold is determined based on the fifth file storage limit. The fifth file storage limit is the file storage limit of a full directory structure with a layer number that is one less than the current directory layer number of the target directory structure and conforms to the directory layering rules. The current directory layer number is greater than 1.

[0137] In this embodiment, after deleting files in the target directory structure, the number of directory levels in the target directory structure can be dynamically reduced based on changes in the number of files, thereby reducing the number of empty directories and avoiding wasting storage space.

[0138] Specifically, after deleting a file in the target directory structure, it can be checked whether the number of files currently stored in the target directory structure is less than the threshold for reducing the directory level. The threshold for reducing the directory level can be determined based on the fifth file storage limit, which is the maximum number of files that can be stored in a full directory structure with one less level than the current directory level of the target directory structure and that conforms to the directory hierarchy rules. In a specific implementation, the threshold for reducing the number of directory levels can be directly adopted as the upper limit of the fifth file storage quantity. That is, when a directory structure with one less level than the target directory structure can store the currently stored file, it indicates that there are many empty directory entries, low-level directory entries that are not full of files, or directory entries that are not full of subdirectories in the target directory structure. In this case, in order to avoid wasting storage space, the number of directory levels can be reduced, thereby reducing the number of directory entries. The threshold for reducing the number of directory levels can also be calculated using the upper limit of the fifth file storage quantity, for example, by multiplying it by a percentage (e.g., 50%). That is, when a directory structure with one less level than the target directory structure can store the currently stored file and there is still extra storage space, one level of directory can be reduced to avoid the situation where the number of directory levels needs to be increased immediately after reducing the number of directory levels due to the addition of new files.

[0139] Step B20: If the value is less than the target directory structure, then the files stored under the current bottom-level directory entry of the target directory structure are transferred to the second-to-last directory entry of the target directory structure. After the transfer, the empty directory entries in the target directory structure that do not store files are deleted, and the storage path associated with the unique identifier of the transferred files is updated.

[0140] When the number of files currently stored in the target directory structure is less than the threshold for reducing directory levels, the number of levels in the target directory structure can be reduced. That is, files stored under the current bottom-level directory entry in the target directory structure can be moved to the second-to-last directory entry. In this embodiment, there is no restriction on which directory entry in the second-to-last level the files stored under the current bottom-level directory entry can be moved to. In some implementations, files can be moved according to certain rules to store all files with the fewest possible directory entries, avoiding the use of unnecessary directory entries and wasting storage space.

[0141] After moving files stored in the current bottom-level directory to the second-to-last level directory, empty directory entries can be deleted to avoid wasting storage space.

[0142] Update the storage path associated with the unique identifier of the transferred file so that the file can still be found in the target directory structure based on its unique identifier after the file is transferred.

[0143] It is understandable that after the files stored under the current bottom-level directory are moved to the second-to-last level directory, the current bottom-level directory is no longer the bottom-level directory, and the second-to-last level directory becomes the bottom-level directory.

[0144] Further, in one embodiment, step B20, which involves transferring files stored under the current bottom-level directory entry of the target directory structure to the second-to-last directory entry of the target directory structure, includes:

[0145] Step B201: Transfer the files stored under the current bottom-level directory entry of the target directory structure to the second-to-last directory entry of the target directory structure according to the transfer rules, wherein the transfer rules include starting to store files under another directory entry only after the current directory entry is full.

[0146] To avoid wasting storage space, files stored in the current bottom-level directory of the target directory structure can be moved to the second-to-last level directory according to a certain transfer rule. This transfer rule specifically includes storing files in a new directory only after the previous directory is fully filled. Furthermore, in one embodiment, files in the bottom-level directory can be transferred sequentially according to the creation time of the second-to-last level directory entries; that is, files in the bottom-level directory can be moved first to the second-to-last level directory entry with the earliest creation time.

[0147] Furthermore, in one embodiment, after step S30, the method further includes:

[0148] Step C10: When a triggering event is detected that requires adjustment of the directory level of the target directory structure, check whether the system is in a preset idle state;

[0149] In this embodiment, when a triggering event requiring adjustment of the directory hierarchy of the target directory structure is detected, the system can first be checked to see if it is in a preset idle state. The triggering event requiring adjustment of the directory hierarchy of the target directory structure is not limited in this embodiment. For example, it could be that after adding a file to the target directory structure, the number of files currently stored in the target directory structure exceeds a threshold for adding a new directory hierarchy; or it could be that after deleting a file from the target directory structure, the number of files currently stored in the target directory structure is less than a threshold for reducing the directory hierarchy. The preset idle state can be set as needed and is not limited here. For example, it can be set to a state where CPU utilization is below a certain threshold, or a state where the number of CPUs in use is below a certain number, or a state set based on network communication bandwidth, memory usage, IO utilization, etc.

[0150] Step C20: If the target directory structure is in a preset idle state, adjust the number of directory levels according to the triggering event.

[0151] When the system is determined to be in a preset idle state, files stored in the underlying directory entries of the target directory structure are moved according to the triggered event. For example, when it is necessary to increase the number of directory levels, the files are moved to the newly created subdirectory entries to increase the number of directory levels. Or, when it is necessary to reduce the number of directory levels, the files are moved to the second-to-last directory entries to reduce the number of directory levels.

[0152] Step C30: If the system is not in a preset idle state, then use the second preset percentage of the total system resources to adjust the number of directory layers in the target directory structure according to the triggering event.

[0153] When it is determined that the system is not in a preset idle state, in one embodiment, the number of directory levels can be left unchanged until the system is in a preset idle state before making adjustments. In another embodiment, a second preset percentage of the system's total resources can be used to adjust the number of directory levels to avoid affecting the system's normal business processing. The second preset percentage can be set as needed and is not limited in this embodiment.

[0154] Furthermore, embodiments of the present invention also propose a computer-readable storage medium storing a file storage program, wherein the file storage program, when executed by a processor, implements the steps of the file storage method described below.

[0155] The various embodiments of the file storage device and computer-readable storage medium of the present invention can be referred to the various embodiments of the file storage method of the present invention, and will not be repeated here.

[0156] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0157] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0158] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0159] The above are merely preferred embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A file storage method, characterized in that, The file storage method includes the following steps: The number of files to be stored is obtained, and the directory hierarchy rules are obtained. The directory hierarchy rules include the upper limit of the number of directory entries corresponding to each level of directory and the upper limit of the number of first files to be stored corresponding to each bottom-level directory entry. The bottom-level directory entry is the directory entry under the lowest level directory in each level of directory. The target number of layers is calculated based on the number of files and the directory hierarchy rules, wherein the number of files is less than or equal to the second file storage limit and greater than the third file storage limit, the second file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers and conforming to the directory hierarchy rules, and the third file storage limit is the file storage limit of a full directory structure with the number of layers equal to the target number of layers minus one and conforming to the directory hierarchy rules. Create a target directory structure with the target number of layers and conforming to the directory hierarchy rules, store the files to be stored in the bottom directory of the target directory structure, and associate the unique identifier of each file to be stored with the storage path in the target directory structure. The file storage method further includes: When a new file is added to the target directory structure, it is detected whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the number of new directory layers. The threshold for triggering the number of new directory layers is determined based on the fourth file storage limit. The fourth file storage limit is the file storage limit of a full directory structure with the current directory layer number of the target directory structure and that conforms to the directory layering rules. If the value is greater than the target directory, a new subdirectory entry is created for the current bottom-level directory entry of the target directory structure according to the directory hierarchy rules, and the files stored under the current bottom-level directory entry are moved to the newly created subdirectory entry. The storage path associated with the unique identifier of the moved file is updated.

2. The file storage method as described in claim 1, characterized in that, The file storage method is applied to a file storage system, and before the step of obtaining the number of files to be stored, it further includes: When the file storage system receives a file for the first time after its initial startup, the received file will be used as the file to be stored; or, Whenever the file storage system receives a file, it uses the files already stored in the file storage system and the received file as the file to be stored; or, Whenever the file storage system receives a file, it uses the received file as the file to be stored.

3. The file storage method as described in claim 1, characterized in that, The step of creating a target directory structure with the target number of layers and conforming to the directory hierarchy rules, and storing the file to be stored in the bottom directory entry of the target directory structure, includes: Create a target directory structure with the target number of layers, conforming to the directory hierarchy rules, and having a maximum file storage limit equal to the number of files, and store the files to be stored in the bottom directory entry of the target directory structure.

4. The file storage method as described in claim 1, characterized in that, Before the step of detecting whether the number of files currently stored in the target directory structure is greater than the threshold for triggering the addition of new directory levels, the method further includes: When a new file is added to the target directory structure, the upper limit of the storage quantity of the fourth file is calculated; The upper limit of the number of fourth files stored is multiplied by the first preset percentage to obtain the threshold for triggering the number of new directory layers.

5. The file storage method as described in claim 1, characterized in that, The step of creating a new subdirectory entry for the current bottom-level directory entry of the target directory structure according to the directory hierarchy rules, and transferring the files stored under the current bottom-level directory entry to the newly created subdirectory entry includes: According to the directory hierarchy rules, a target number of subdirectory entries are created for the current bottom-level directory entries of the target directory structure. The number of files currently stored in the target directory structure is less than or equal to the upper limit of the number of files stored in the subdirectory entries of the target number, and is greater than the upper limit of the number of files stored in the subdirectory entries of the target number minus one number. Move the files stored in the current underlying directory to the newly created subdirectory.

6. The file storage method as described in claim 1, characterized in that, After the step of associating and storing the unique identifier of each file to be stored with its storage path in the target directory structure, the method further includes: After deleting a file in the target directory structure, it is detected whether the number of files currently stored in the target directory structure is less than the threshold for reducing the number of directory levels. The threshold for reducing the number of directory levels is determined based on the fifth file storage limit. The fifth file storage limit is the file storage limit of a full directory structure with a number of levels equal to the current number of directory levels in the target directory structure minus one level, and which conforms to the directory layering rules. The current number of directory levels is greater than 1. If the file is less than the target directory structure, the files stored in the current bottom-level directory entry of the target directory structure are transferred to the second-to-last directory entry of the target directory structure according to the transfer rules. After the transfer, empty directory entries without stored files in the target directory structure are deleted, and the storage path associated with the unique identifier of the transferred file is updated. The transfer rules include starting storage in another directory entry only after the first directory entry is fully stored.

7. The file storage method as described in claim 1, characterized in that, After the step of associating and storing the unique identifier of each file to be stored with its storage path in the target directory structure, the method further includes: When a triggering event is detected that requires adjustment of the directory hierarchy of the target directory structure, the system checks whether it is in a preset idle state. If the target directory structure is in a preset idle state, the number of directory levels is adjusted according to the triggering event. If the system is not in a preset idle state, then the number of directory layers in the target directory structure is adjusted according to the triggering event using the second preset percentage of the total system resources.

8. The file storage method according to any one of claims 1 to 7, characterized in that, After the step of associating and storing the unique identifier of each file to be stored with its storage path in the target directory structure, the method further includes: Determine the target historical files whose last access time was before a preset time from each file stored in the target directory structure; Each of the target historical files is extracted from the target directory structure and compressed into a single compressed file; The compressed file is stored as a new file in the underlying directory of the target directory structure.

9. A file storage device, characterized in that, The file storage device includes: a memory, a processor, and a file storage program stored on the memory and executable on the processor, wherein the file storage program, when executed by the processor, implements the steps of the file storage method as described in any one of claims 1 to 8.