A method for automatically replacing project file names in batches
By adopting batch automatic replacement method in software project development, using whitelist filtering and regular matching to automatically replace file names, the time-consuming and labor-intensive and error-prone problem of manual replacement is solved, and efficient and accurate file name replacement is achieved.
Patent Information
- Application Number
- CN201911313733.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-19
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2039-12-19
AI Technical Summary
During the software project development process, the code naming is not uniform, resulting in file name replacement when code sorting, archive or migration. Manual replacement is time-consuming and labor-intensive and error-prone, especially in large projects.
Use the automatic batch replacement method of project file names, set filtering conditions in the whitelist, traversing and obtaining files in the project directory, filtering out files that need to be replaced, and using regular matching and complete search mode to find files that need to be replaced in the file content name, automatically replace and write to the original file.
It realizes the organization and replacement of a large number of files and codes in a short time, reduces the time cost and error rate of manual replacement, and improves the accuracy and efficiency of replacement.
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of project management, and in particular to a method for automatically replacing project file names in batches. Background Art
[0002] In the process of software project development, due to the personal habits of developers, code naming is not necessarily unified. When the code is archived or migrated to a new project, a unified naming arrangement is required. Replacing a file name requires modifying several related codes, which is not only time-consuming and labor-intensive, but also prone to errors. The workload of replacement in large projects will increase exponentially. In the process of arranging old projects and migrating codes, file name arrangement and replacement are often required. Manual replacement will take a lot of time and energy, and is prone to errors.
[0003] Therefore, the prior art has defects and needs to be improved. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method for automatically replacing project file names in batches in view of the deficiencies in the prior art.
[0005] The technical solution of the present invention is as follows:
[0006] A method for automatically replacing project file names in batches, first adding a filtering condition to a whitelist, traversing all files in the project directory according to the filtering condition, and filtering out files that need to be replaced; then obtaining all code file names and file contents that may need to be modified, performing regular matching in the file contents that may need to be modified, and modifying and replacing them if the match is successful; finally writing the replaced content into the original file.
[0007] The method for automatically replacing project file names in batches comprises the following specific steps:
[0008] Step 1: Filtering step: Set up a whitelist of filtering conditions, and filter out the files that need to be replaced by adding filtering conditions such as file name, file type, or folder path in the whitelist;
[0009] Step 2: Smart deduplication step: For the filtered code file, first read the content in the code file. If the code file references the file name, only the code file is loaded; if the code file uses the code in the content of the file corresponding to the file name, the code file and its header file need to be loaded. If the code file does not use the code in the content of the file corresponding to the file name and does not reference the file name, no content needs to be loaded. Only the content that may need to be modified is read into the memory;
[0010] Step 3: Read the replacement rules desired by the user;
[0011] Step 4: The system will traverse the file contents in the memory and use regular expressions to find the file name that needs to be replaced; if the regular expression does not match, it will intelligently switch to full search mode, traversing all file contents and performing string search to ensure that there are no omissions.
[0012] Step 5: Replace the search results in the memory and write them back to the original file when all replacements are completed.
[0013] The method for automatically replacing project file names in batches, wherein the screening conditions include the file name, file type or folder path.
[0014] The method for automatically replacing project file names in batches has replacement rules as follows: precise replacement of original names, batch addition of prefixes, batch replacement of prefixes, and batch filtering of prefixes. It also supports simple replacement. You only need to enter the current prefix, and it will intelligently determine whether a new prefix needs to be added or replaced.
[0015] The method for automatically replacing project file names in batches uses the following regular expression matching rules: using the original file name as a keyword, matching the word boundaries at both ends of the keyword in all file contents; a word boundary is the boundary between a word and a symbol, and after matching the word boundary, continue to match whether a plus sign appears before and after. If there is a word boundary and no plus sign appears, the match is successful, indicating that replacement is required.
[0016] In the method for automatically replacing project file names in batches, words can be Chinese characters, English characters and numbers; symbols can be Chinese symbols, English symbols, spaces, tabs and line breaks.
[0017] The present invention can complete the sorting and replacement of 3,000 files and 500,000 lines of code within 10 minutes, thus solving the problem of long manual replacement time and easy error. DETAILED DESCRIPTION
[0018] The present invention is described in detail below in conjunction with specific embodiments.
[0019] The present invention provides a file whitelist specified rule replacement function, which can easily replace the target format. First, by adding filtering conditions such as file name, file type or folder path in the whitelist, all files in the project directory are traversed according to the filtering conditions to filter out the files that need to be replaced.
[0020] Then obtain all code file names and file contents that may need to be modified, perform regular matching on the file contents that may need to be modified, and modify and replace them if the match is successful.
[0021] Finally, the replaced content is written into the original file. Here, you can replace according to user-defined rules or use the default rules.
[0022] The specific steps include:
[0023] Step 1: Filtering step: Set up a whitelist of filtering conditions. By adding filtering conditions such as file name, file type or folder path in the whitelist, filter out the files that need to be replaced. It supports filtering the target code files in three ways: "path", "file name" and "file type". This filtering can greatly speed up the processing speed.
[0024] Step 2: Smart deduplication step: After filtering the code file, first read the content of the code file. If the code file references the file name, only the code file is loaded. If the code file uses the code in the content of the file corresponding to the file name, the code file and its header file need to be loaded. If the code file does not use the code in the content of the file corresponding to the file name and does not reference the file name, no content needs to be loaded. Only the content that may need to be modified is read into the memory.
[0025] For example, in iOS software development, a class consists of two files: the header file "class name.h" and the source file "class name.m". Step 1 Filter the selected files to remove duplicates and obtain a set of non-repeating class names. Search for these class names in all files in the project. For each file, the following two conditions need to be judged: Condition 1, whether these class names are referenced in the file (that is, the header file is used). Condition 2, whether instance objects are created or methods are called through these class names in the file (that is, the source file is used). As long as condition 2 is met, the header file and source file of the class corresponding to the file need to be loaded at the same time. If only condition 1 is met, only the header file of the class corresponding to the file needs to be loaded. If neither is met, no loading is required. By analyzing, only the content that may need to be modified is read into memory, which speeds up the processing speed of the program. (Class is the basis for information encapsulation in object-oriented programming. A class is a user-defined reference data type, also known as a class type. Each class contains a data description and a set of functions that operate data or pass messages. An instance of a class is called an object.)
[0026] Step 3: Read the replacement rules that the user wants, for example, the replacement rules are: exact replacement of original name, batch addition of prefixes, batch replacement of prefixes, batch filtering of prefixes. Simple replacement is also supported. You only need to enter the current prefix, and it will intelligently determine whether a new prefix needs to be added or replaced.
[0027] Step 4: The system will traverse the file contents in the memory and use regular expressions to find the file name that needs to be replaced.
[0028] A regular expression describes a string matching pattern, which can be used to check whether a string contains a certain substring, replace the matched substring, or extract a substring that meets a certain condition from a string, etc. By analyzing common files and common names in iOS and conducting a large number of experiments, the key matching rules of the present invention are finally obtained, and the target file name is matched by the word boundary and conditional filtering of the regular expression.
[0029] The specific matching rules are as follows: Use the original file name as the keyword, and match the word boundaries at both ends of the keyword in all file contents; the word boundary is the boundary between words and symbols, and words can be Chinese characters, English characters, and numbers. Symbols can be Chinese symbols, English symbols, spaces, tabs, and line breaks. After matching the word boundary, continue to match whether there is a plus sign before and after. If there is a word boundary and no plus sign appears, the match is successful, indicating that replacement is required.
[0030] Through this rule, the content that needs to be replaced can be matched accurately and quickly.
[0031] In addition, a full search mode is also provided. If no match is found through the regular expression, the full search mode will be switched intelligently to traverse all file contents and perform string search to ensure that no omissions occur.
[0032] Step 5: Replace the searched results in the memory, and write them back to the original file after all replacements are completed. This can avoid frequent reading of files and greatly improve the running speed of the program.
[0033] The present invention can complete the sorting and replacement of 3,000 files and 500,000 lines of code within 10 minutes, thus solving the problem of long manual replacement time and easy error.
[0034] For example, in the process of organizing the iOS client code of lemo app, we need to replace all the file names under the project "Modules" directory and its subdirectories. Some of these files start with "YW" and some are directly named after the content. We need to replace the file names starting with "YW" with those starting with "VST". For those named directly after the content, we need to add "VST" in front. At the same time, it is also necessary to replace the places where this file is referenced in all code files in the project. Through the present invention, we only need to make a simple setting to complete this task quickly and accurately.
[0035] First, we set the path of the project file to be replaced " / VostucIOS / Modules". Then add the suffix set of the file types that need to be replaced to the whitelist "[c,m,h,mm,pch]", where c,m,h,mm,pch all represent a suffix. The file suffix is used for filtering, and multiple types of suffixes are separated by commas.
[0036] Finally, set the rules that need to be replaced. For example, here we set "YW" to be replaced with "VST", and click to execute. After waiting for the processing to be completed, all the file names in the specified path are added or replaced with file names starting with "VST". In addition, in the entire project code, if there are references to files under the path, they are all automatically matched and modified. Through the present invention, the time cost is greatly reduced, the accuracy of replacement is increased, and the task is completed better and faster.
[0037] It should be understood that those skilled in the art can make improvements or changes based on the above description, and all these improvements and changes should fall within the scope of protection of the appended claims of the present invention.
Claims
1. A method for automatically replacing project file names in batches, characterized in that: Step 1: First, add a filter condition to the whitelist, and traverse all the files in the project directory according to the filter condition to filter out the files that need to be replaced; Step 2: Then obtain all code file names and file contents that may need to be modified; Step 3: Perform regular matching in the file contents that may need to be modified, and modify and replace them if the match is successful; Step 4: Finally, write the replaced content into the original file; The specific method is: Step 1: Filtering step: Set up a whitelist of filtering conditions, and filter out the files that need to be replaced by adding filtering conditions to the whitelist; Step 2: Intelligent deduplication step: After filtering, read the content in the code file first. If the code file references the file name, only load the code file; If the code file uses the code in the content of the file corresponding to the file name, then the code file and its header file need to be loaded. If the code file does not use the code in the content of the file corresponding to the file name and does not reference the file name, then no content needs to be loaded. Only the content that may need to be modified is read into the memory. Step 3: Read the replacement rule that the user wants; the system will traverse the file contents in the memory and use regular expressions to find the file name to be replaced; if the regular expression does not match, it will intelligently switch to full search mode, traversing all file contents and performing string search to ensure that there are no omissions; Step 4: Replace the search results in the memory and write them back to the original file when all replacements are completed.
2. The method for automatically replacing project file names in batches according to claim 1, characterized in that: Filter criteria include file name, file type or folder path.
3. The method for automatically replacing project file names in batches according to claim 1, characterized in that: The replacement rules are: precise replacement of original names, batch addition of prefixes, batch replacement of prefixes, batch filtering of prefixes. It also supports simple replacement. You only need to enter the current prefix and it will intelligently determine whether a new prefix needs to be added or replaced.
4. The method for automatically replacing project file names in batches according to claim 1, characterized in that: The matching rule of the regular expression is: use the original file name as the keyword, and match the word boundaries at both ends of the keyword in all file contents; the word boundary is the boundary between a word and a symbol, and after matching the word boundary, continue to match whether there is a plus sign before and after it; if there is a word boundary and no plus sign appears, the match is successful, indicating that replacement is required.
5. The method for automatically replacing project file names in batches according to claim 4, characterized in that: Words include Chinese characters, English characters and numbers; symbols include Chinese symbols, English symbols, spaces, tabs and line breaks.
Citation Information
Patent Citations
Method and device for multi-language version development and replacement
CN101667118A
File name altering method and electronic device
CN104462191A
