A method and device for searching useless files
By analyzing the directory index files and generating dependency network of the software development project, useless files are automatically filtered out, which solves the problem of useless files remaining in the software development project, and improves the software maintenance efficiency and development progress.
Patent Information
- Application Number
- CN202411794681.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-08
AI Technical Summary
In software development projects, useless files of old versions of software remain in the new version of software, resulting in increased software size, increased maintenance difficulty and slow development progress.
By analyzing the directory index file of the software development project, determining the path and name of each file, distinguishing code files and resource files, recording the dependencies of the code files, generating a complete dependency network, and filtering out files corresponding to independent subnets that do not contain the entry function as useless files.
It realizes automated search of useless files in software development projects, reduces software volume, reduces maintenance difficulty, and improves development progress.
Smart Images

Figure CN119781801A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to a method for finding useless files in a software development project. Background Art
[0002] Software development is a product development process that builds software according to user requirements. In a software development project, as the software version is constantly updated, various types of files are constantly added to the software development project to meet usage requirements. Sometimes there are some useless files that are needed by the old version of the software but no longer needed by the new version of the software. These useless files still remain in the new version of the software, resulting in an increase in the size of the software, increasing the difficulty of later maintenance, and slowing down the progress of software development. Summary of the invention
[0003] The technical problem to be solved by this application is: how to automatically find useless files in software development projects.
[0004] To solve the above technical problems, the present application proposes a method for finding useless files, comprising the following steps. Step S1: Find the paths and names of all files in the software development project according to the directory index file of the software development project. Step S2: Divide all files of the software development project into two categories according to the file suffix: code files and resource files; code files refer to files that reference other code files and / or rely on resource files; resource files refer to files that do not reference code files or rely on other resource files. Step S3: Determine and record the dependency relationship of each code file; when code file A references code file B, it is determined that code file A depends on code file B; when code file A contains the name of resource file D, it is determined that code file A depends on resource file D. Step S4: Merge the dependencies of all code files to generate a complete dependency network of all code files. Step S5: The file where the entry function at the beginning of the software development project is located is called the main file. In the complete dependency network of all code files, the files corresponding to the independent subnets that do not contain the main file are regarded as useless files.
[0005] Preferably, in step S1, the file screening scope of the software development project is determined according to the specified keywords and / or suffix names. In step S2, all files within the screening scope of the software development project are divided into two categories according to the file suffix names: code files and resource files. In step S3, the dependency relationship of each code file within the screening scope is determined and recorded. In step S4, the dependency relationships of all code files within the screening scope are merged to generate a complete dependency network of all code files within the screening scope. In step S5, in the complete dependency network of all code files within the screening scope, the files corresponding to the independent subnets that do not contain the main file are treated as useless files.
[0006] Preferably, in step S2, files with suffixes of .c or .cpp or .cxx or .h or .m or .java or .py or .js or .ts or .html or .htm or .css or .php or .rb or .go or .swift or .kotlin are code files; files with suffixes of .txt or .json or .xml or .png or .jpg or .jpeg or .gif or .bmp or .mp3 or .wav or .aac or .mp4 or .avi or .mov or .pdf or .zip or .tar or .gz or .db or .sqlite or .ttf or .otf are resource files.
[0007] Furthermore, in step S3, the referenced code files and dependent resource files are collectively referred to as having a dependency relationship.
[0008] Furthermore, in step S4, by continuously traversing the dependencies of all code files and merging the dependencies of the next layer of code files, a complete dependency network of all code files is finally generated.
[0009] Furthermore, in step S4, the complete dependency network of all code files is composed of multiple independent subnetworks.
[0010] Preferably, in step S5, if a certain file is not in the independent subnet including the main file in the complete dependency network of all code files, it is manually determined whether it is a useless file.
[0011] Preferably, in step S5, one or more code files and / or resource files are placed in a whitelist, and files in the whitelist are not considered useless files. At this time, in step S5, if a file is not in an independent subnet containing the main file in the complete dependency network of all code files, and is not in the whitelist, it is manually determined whether it is a useless file.
[0012] The present application also proposes a device for finding useless files, including a search unit, a classification unit, a dependency determination unit, a dependency network generation unit, and a useless file screening unit. The search unit is used to find the paths and names of all files in the software development project according to the directory index file of the software development project. The classification unit is used to classify the files of the software development project into two categories according to the suffix of the file: code files and resource files; code files refer to files that reference other code files and / or rely on resource files; resource files refer to files that do not reference code files or rely on other resource files. The dependency determination unit is used to determine and record the dependency relationship of each code file; when code file A references code file B, it is determined that code file A depends on code file B; when code file A contains the name of resource file D, it is determined that code file A depends on resource file D. The dependency network generation unit is used to merge the dependency relationships of code files to generate a complete dependency network of all code files. The useless file screening unit is used to call the file where the entry function at the beginning of the software development project is located as the main file, and in the complete dependency network of all code files, the files corresponding to the independent subnet that does not contain the main file are regarded as useless files.
[0013] The technical effect achieved by this application is: a dependency network between files is generated based on the imported project directory file (also called directory index file), all useless files are screened out in combination with filtering rules, and the search results are accurate and comprehensive. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 It is a flowchart of the method for finding useless files proposed in this application.
[0015] Figure 2 is a schematic diagram of a first example of step S3.
[0016] Figure 3 is a schematic diagram of a second example of step S3.
[0017] Figure 4 is a diagram of an example of a complete dependency network of all code files.
[0018] Figure 5 is a diagram of another example of a complete dependency network for all code files.
[0019] Figure 6 It is a structural schematic diagram of the device for searching useless files proposed in this application.
[0020] Explanation of the reference numerals in the figure: searching unit 1, classification unit 2, dependency determination unit 3, dependency network generation unit 4, useless file screening unit 5. DETAILED DESCRIPTION
[0021] See also Figure 1 ,The method for finding useless files proposed in this application includes the following steps.
[0022] Step S1: Set the path or name of the directory index file of the software development project, import the directory index file of the software development project, and find the paths and names of all files in the software development project according to the directory index file.
[0023] Preferably, this step determines the file search scope based on the specified keywords and / or suffixes. On the one hand, files whose file names contain a certain keyword are designated as search objects, such as files whose file names contain "work" as search objects. On the other hand, a certain file type is designated as a search object, such as files with suffixes .h and .m as search objects. For large-scale software projects, determining the search scope can greatly increase the speed of generating the complete dependency network in the subsequent step S4.
[0024] Step S2: All files in the software development project that are within the scope of investigation (the default investigation scope is all files) are divided into two categories according to the file suffix: code files and resource files. Code files refer to files that reference other code files and / or rely on resource files. A code file may be referenced by other code files. Resource files refer to files that do not reference code files or rely on other resource files. Resource files are only relied on by code files.
[0025] For example, files with suffixes of .c or .cpp or .cxx or .h or .m or .java or .py or .js or .ts or .html or .htm or .css or .php or .rb or .go or .swift or .kotlin are code files. Files with suffixes of .txt or .json or .xml or .png or .jpg or .jpeg or .gif or .bmp or .mp3 or .wav or .aac or .mp4 or .avi or .mov or .pdf or .zip or .tar or .gz or .db or .sqlite or .ttf or .otf are resource files. The above are only examples of common suffixes, not exhaustive.
[0026] Step S3: Determine and record the dependency relationship of each code file within the scope of the software development project. When code file A references (imports) code file B, it is determined that code file A depends on code file B. When code file A contains the name of resource file D, it is determined that code file A depends on resource file D. This step refers to the referenced code files and dependent resource files as having dependencies.
[0027] See also Figure 2 This is the first example of step S3. Code file A references code files B, C, and E. Code file A also contains the name of resource file D, so it is determined that code file A depends on code files B, C, E, and resource file D.
[0028] See also Figure 3 This is the second example of step S3. Code file E refers to code files C, F, and G, so it is determined that code file E depends on code files C, F, and G.
[0029] Step S4: The dependencies of all code files are merged to generate a complete dependency network of all code files within the scope of investigation of the software development project.
[0030] Below Figure 2 and Figure 3 Take step S4 as an example. Select any code file A (main node), traverse all dependencies (child nodes) of code file A, that is, find all files B, C, D, E that code file A depends on. Then traverse all dependencies (grandchild nodes) of all code files B, C, E (child nodes) that code file A depends on, and then find all files C, F, G that code file E depends on, and merge all dependencies (grandchild nodes) of code file E (child node) into the dependency of code file A (main node), as shown in the following figure. Figure 4 shown. Figure 4 In the code file, curly brackets are used to indicate references between code files, and arrows are used to indicate the dependency of code files on resource files. Both of these belong to dependency relationships. By continuously traversing the dependency relationships of all code files and merging the dependency relationships of the next layer of code files, a complete dependency network of all code files is finally generated.
[0031] See also Figure 5 , which is another example of a complete dependency network for all code files. Figure 5 Arrows are used to indicate the dependencies of code files on other files, including references between code files and dependencies of code files on resource files. File C points to file D through an arrow, indicating that code file C depends on file D. The bidirectional arrow between file A and file B indicates that code file A depends on file B, and code file B also depends on file A.
[0032] Step S5: The file containing the entry function at the beginning of the software development project is called the main file. In the complete dependency network of all code files within the scope of investigation in the software development project, the files corresponding to the independent subnet containing the main file are retained, and the files corresponding to the independent subnet not containing the main file are regarded as useless files. Figure 5 For example, Figure 5The complete dependency network of the code files shown includes two independent subnets, subnet 1 consists of files A and B, and subnet 2 consists of files C, D, E, F, G, and H. Assuming that file G is the main file and the main file appears in subnet 2, the file corresponding to subnet 1 is regarded as a useless file.
[0033] Optionally, if a certain file is not in an independent subnet including the main file in the complete dependency network of all code files within the scope of investigation of the software development project, it is handed over to manual labor to further determine whether it is a useless file.
[0034] Optionally, one or more code files and / or resource files are placed in a whitelist, and files in the whitelist are never considered useless files. At this point, if a file is not in the independent subnet containing the main file in the complete dependency network of all code files within the scope of the investigation of the software development project, and is not in the whitelist, it is handed over to manual further judgment to determine whether it is a useless file.
[0035] See also Figure 6 The device for searching for useless files proposed in the present application includes a searching unit 1, a classification unit 2, a dependency determination unit 3, a dependency network generation unit 4, and a useless file screening unit 5. Figure 6 The device shown corresponds to Figure 1 The method shown.
[0036] The search unit 1 is used to find the paths and names of all files in the software development project according to the directory index file of the software development project.
[0037] The classification unit 2 is used to classify the files of the software development project into two categories according to the file suffixes: code files and resource files. Code files refer to files that reference other code files and / or rely on resource files. Resource files refer to files that do not reference code files and do not rely on other resource files.
[0038] The dependency determination unit 3 is used to determine and record the dependency of each code file. When code file A references code file B, it is determined that code file A depends on code file B. When code file A contains the name of resource file D, it is determined that code file A depends on resource file D.
[0039] The dependency network generating unit 4 is used to merge the dependencies of the code files to generate a complete dependency network of all code files.
[0040] The useless file screening unit 5 is used to call the file containing the entry function starting from the software development project as the main file, and in the complete dependency network of all code files, the files corresponding to the independent subnet that does not contain the main file are regarded as useless files.
[0041] Each software development project has a project directory file. This application obtains the project directory file, analyzes the index relationship of the project directory file, generates the dependency relationship between files, and thus generates the file relationship dependency network of the entire software development project. Finally, the file relationship dependency network is traversed, and the final useless files are obtained by combining whether each independent subnet contains the main file.
[0042] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.
Claims
1. A method for finding useless files, characterized in that: The method comprises the following steps: Step S1: Find the paths and names of all files in the software development project according to the directory index file of the software development project; Step S2: Divide all the files of the software development project into two categories according to the file suffixes: code files and resource files; code files refer to files that reference other code files and / or rely on resource files; resource files refer to files that do not reference code files and do not rely on other resource files; Step S3: Determine and record the dependency relationship of each code file; when code file A references code file B, it is determined that code file A depends on code file B; when code file A contains the name of resource file D, it is determined that code file A depends on resource file D; Step S4: Merge the dependencies of all code files to generate a complete dependency network of all code files; Step S5: The file containing the entry function that starts the software development project is called the main file. In the complete dependency network of all code files, the files corresponding to the independent subnet that does not contain the main file are regarded as useless files.
2. The method for searching for useless files according to claim 1, wherein: In step S1, the file screening scope of the software development project is determined according to the specified keywords and / or suffix names; In step S2, all files within the scope of the software development project are divided into two categories according to the file suffixes: code files and resource files; In step S3, the dependency relationship of each code file within the scope of investigation is determined and recorded; In step S4, the dependency relationships of all code files within the scope of investigation are merged to generate a complete dependency network of all code files within the scope of investigation; In step S5, in the complete dependency network of all code files within the scope of investigation, the files corresponding to the independent subnets that do not include the main file are regarded as useless files.
3. The method for searching for useless files according to claim 1, wherein: In step S2, the file with the suffix .c or .cpp or .cxx or .h or .m or .java or .py or .js or .ts or .html or .htm or .css or .php or .rb or .go or .swift or .kotlin is a code file; the file with the suffix .txt or .json or .xml or .png or .jpg or .jpeg or .gif or .bmp or .mp3 or .wav or .aac or .mp4 or .avi or .mov or .pdf or .zip or .tar or .gz or .db or .sqlite or .ttf or .otf is a resource file.
4. The method for searching for useless files according to claim 1, wherein: In step S3, the referenced code files and dependent resource files are collectively referred to as having a dependency relationship.
5. The method for searching for useless files according to claim 1, wherein: In step S4, by continuously traversing the dependencies of all code files and merging the dependencies of the next layer of code files, a complete dependency network of all code files is finally generated.
6. The method for searching for useless files according to claim 1, wherein: In step S4, the complete dependency network of all code files is composed of multiple independent subnetworks.
7. The method for searching for useless files according to claim 1, wherein: In step S5, if a certain file is not in the independent subnet including the main file in the complete dependency network of all code files, it is handed over to manual to further determine whether it is a useless file.
8. The method for searching for useless files according to claim 1, wherein: In step S5, one or more code files and / or resource files are placed in a white list, and the file clocks in the white list are not regarded as useless files.
9. The method for finding useless files according to claim 8, characterized in that: In step S5, if a certain file is not in the independent subnet including the main file in the complete dependency network of all code files, and is not in the whitelist, it is handed over to manual further determination whether it is a useless file.
10. A device for searching for useless files, characterized in that: It includes a search unit, a classification unit, a dependency determination unit, a dependency network generation unit, and a useless file screening unit; The search unit is used to find the paths and names of all files in the software development project according to the directory index file of the software development project; The classification unit is used to classify the files of the software development project into two categories according to the file suffixes: code files and resource files; code files refer to files that reference other code files and / or rely on resource files; resource files refer to files that do not reference code files and do not rely on other resource files; The dependency determination unit is used to determine and record the dependency of each code file; when code file A references code file B, it is determined that code file A depends on code file B; when code file A contains the name of resource file D, it is determined that code file A depends on resource file D; The dependency network generating unit is used to merge the dependency relationships of the code files to generate a complete dependency network of all code files; The useless file screening unit is used to call the file containing the entry function starting from the software development project the main file, and in the complete dependency network of all code files, the files corresponding to the independent subnet that does not contain the main file are regarded as useless files.
Citation Information
Cited By
Method and device for automatically shooting multi-page document with repeated content and stability detection
CN120877170A