File renaming method and device based on file content, equipment and medium

By extracting structured key information from file content using a large model and generating filenames, the problems of non-standard file naming and missing information are solved, enabling intelligent file renaming and improving file management efficiency.

CN122489504APending Publication Date: 2026-07-31深圳市和讯华谷信息技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
深圳市和讯华谷信息技术有限公司
Filing Date
2026-03-11
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In existing technologies, file naming relies on manual rules, making it difficult to achieve intelligent batch renaming based on content. This results in non-standard file names, missing information, and low efficiency.

Method used

By extracting file content, using a large model combined with dynamic prompts to extract structured key information, and mapping it to a preset naming template to generate filenames, intelligent renaming is achieved by combining file metadata.

Benefits of technology

It achieves deep semantic understanding and intelligent renaming based on file content, reduces reliance on manual rules, improves file retrieval and archiving efficiency, and adapts to diverse application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122489504A_ABST
    Figure CN122489504A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, and medium for file renaming based on file content. The method includes: extracting the file content of the file to be renamed; inputting the file content into a large model, and extracting structured key information from the file content using dynamic prompts; mapping the structured key information to a preset naming template, and generating a filename by combining the file's metadata. Through this method, this application can leverage the powerful natural language processing capabilities of a large model to automatically identify and extract key information, achieving deep semantic understanding and intelligent renaming based on file content. This significantly reduces reliance on manual rules. Furthermore, the introduction of dynamic prompts allows users to change the extraction logic simply by adjusting the natural language prompts, significantly lowering the technical threshold and adapting to various application scenarios. The organic integration of key information extracted by the large model with file metadata greatly improves the efficiency of file retrieval and archiving.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus, device, and medium for renaming files based on file content. Background Technology

[0002] With the widespread adoption of digital office solutions and cloud storage, the number of electronic files generated and managed by users daily is exploding, including various formats such as Word documents, PDF reports, scanned invoices, and screenshots. Traditional file naming relies on manual input, which generally suffers from the following problems: 1. Inconsistent naming conventions: Differences in user habits lead to messy filenames, such as "scanned document 001.pdf" or "new document.docx", making retrieval difficult.

[0003] 2. Missing Information: The file name does not reflect the core content. For example, the invoice file name is "image.jpg" and it is missing key information such as "invoice number", "invoice date" and "amount".

[0004] 3. Low batch efficiency: Existing file managers (such as Windows Explorer and macOS Finder) only support simple renaming based on filename or meta-attributes (such as adding serial numbers or replacing characters), and cannot generate semantic names based on content-driven approaches.

[0005] 4. High reliance on manual labor: Although enterprise document systems have templates, manual filling or writing of complex script configurations is required, which is difficult and prone to errors.

[0006] In existing technologies, some solutions attempt to alleviate the above problems. For example, rule-driven tools rely on predefined regular expressions or fixed extraction logic, which are suitable for structured documents but fail to work with non-standard content (such as handwritten scans and natural language reports). Another solution combines OCR with rules, which can recognize text in images, but still requires manual configuration of rules and lacks intelligence. Summary of the Invention

[0007] This application provides a method, apparatus, device, and medium for renaming files based on file content, in order to solve the problem that file naming in the prior art relies on manual rules and is difficult to achieve intelligent batch renaming based on content.

[0008] To address the aforementioned technical problems, this application provides a file renaming method based on file content. This method includes: Extract the contents of the file to be renamed; The file content is input into a large model, and structured key information in the file content is extracted by combining dynamic prompts. The structured key information is mapped to a preset naming template, and a filename is generated by combining the metadata of the file to be renamed.

[0009] In one optional embodiment of this application, the dynamic prompt words include one or more of user prompt words and system prompt words; The step of inputting the file content into a large model and extracting structured key information from the file content using dynamic prompts includes: Obtain the preset system prompt words, and obtain the user prompt words preset by the user or dynamically input by the user; The file content, the user prompt, and the system prompt are input into the large model. The user prompt guides the large model to identify and extract key information from the file content, and the system prompt constrains the large model to output the structured key information.

[0010] In one optional embodiment of this application, mapping the structured key information to a preset naming template and generating a filename by combining the metadata of the file to be renamed includes: Obtain the preset naming template, which includes key field variables and general field variables; The structured key information is mapped to the key field variables, and the metadata is mapped to the general field variables.

[0011] In one optional embodiment of this application, the preset naming template further includes an auto-incrementing sequence number variable; Before generating the filename, the process also includes: Determine the batch file set to which the file to be renamed belongs, and sort the batch file set according to a preset sorting rule; The auto-incrementing sequence number corresponding to the file to be renamed is determined based on the sorting result, and the auto-incrementing sequence number is mapped to the auto-incrementing sequence number variable.

[0012] In one optional embodiment of this application, extracting the file content of the file to be renamed includes: Identify the file type of the file to be renamed; If the file to be renamed is a document file, then the corresponding document parsing library is called to extract the text content; If the file to be renamed is an image file, then the optical character recognition engine is invoked to extract the text content.

[0013] In an optional embodiment of this application, after generating the filename, the method further includes: Check if the filename already exists in the current storage path; If a conflict exists, mark the file to be renamed as conflicted and return a conflict message to the user.

[0014] In one optional embodiment of this application, the method further includes: A graphical user interface is provided, which includes a rule configuration area and a preview area; In response to the user entering the dynamic prompt word or the preset naming template in the rule configuration area, a preview result of the file name is generated and displayed in the preview area.

[0015] To solve the above-mentioned technical problems, another technical solution adopted in this application is: to provide a file renaming device based on file content. This includes: The first extraction module is used to extract the file content of the file to be renamed. The second extraction module is used to input the file content into the large model and extract the structured key information in the file content in combination with dynamic prompt words; The renaming module is used to map the structured key information to a preset naming template and generate a filename by combining the metadata of the file to be renamed.

[0016] To solve the above-mentioned technical problems, another technical solution adopted in this application is: to provide a computer device, characterized in that the computer device includes: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory to cause the computer device to execute the file renaming method based on file content as described above.

[0017] To solve the above-mentioned technical problems, another technical solution adopted in this application is: to provide a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, characterized in that, when the instructions are executed by a processor, they implement the file renaming method based on file content as described above.

[0018] The beneficial effects of this application are as follows: Unlike existing technologies, this application discloses a method, apparatus, device, and medium for file renaming based on file content. This method extracts file content and, combined with dynamic prompts, leverages the powerful natural language processing capabilities of a large model to automatically identify and extract key information such as "amount," "contractor," and "date," achieving deep semantic understanding and intelligent renaming based on file content, significantly reducing reliance on manual rules. Furthermore, the introduction of dynamic prompts allows users to change the extraction logic simply by adjusting the natural language prompts without modifying code or complex configuration files, significantly lowering the technical threshold and usage cost, and adapting to various application scenarios. By organically integrating the key information extracted by the large model with file metadata, standardized filenames containing core business semantics are automatically generated, allowing users to obtain key information through filenames without opening the file, greatly improving the efficiency of file retrieval and archiving. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort, wherein: Figure 1 This is a flowchart illustrating an embodiment of the file renaming method based on file content provided in this application; Figure 2 This is a schematic diagram of a GUI interface of an embodiment of the file renaming method based on file content provided in this application; Figure 3 This is a schematic diagram of an embodiment of the file renaming device based on file content provided in this application; Figure 4 This is a schematic diagram of the structure of an embodiment of the storage medium provided in this application; Figure 5 This is a schematic diagram of the structure of an embodiment of the computer device provided in this application. Detailed Implementation

[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0021] The terms "first," "second," and "third" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.

[0022] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0023] Those skilled in the art should understand that although the singular form "file to be renamed" is used in the claims and embodiments of this application, this is only for the purpose of clearly explaining the technical details and does not constitute a limitation on the application scenario. In practical applications, "file to be renamed" refers to both a single independent file object and a collection of files containing multiple files.

[0024] Specifically, when processing a single file, the entire process of content extraction, AI recognition, and naming generation is performed directly on that file to meet users' needs for quickly organizing scattered files.

[0025] When processing a batch of files (i.e., the preferred application scenario of this application), the file set is traversed, and the above processing steps are performed on each file in the set sequentially or in parallel. For batch processing scenarios, a set sorting and auto-incrementing sequence number generation mechanism is further introduced to ensure that the batch-generated filenames have a unified format specification and logical order, thereby solving the problems of low efficiency and rigid rules in traditional batch naming techniques. Therefore, although the following embodiments are mainly based on batch processing flows, all the technical features involved are applicable to single-file processing scenarios.

[0026] This application provides a file renaming method based on file content, see reference. Figure 1 , Figure 1This is a flowchart illustrating an embodiment of the file renaming method based on file content provided in this application. The file renaming method based on file content includes: S10: Extract the file content of the file to be renamed.

[0027] Because the files to be renamed come from a wide range of sources and have different formats, they may include document files (such as PDF reports, Word documents, and Excel spreadsheets), image files (such as scanned copies and screenshots), and other types of files. In this application, in order for the subsequent large model to understand the file content, these unstructured or semi-structured file data need to be converted into unified text stream data that can be processed by the model.

[0028] In an optional embodiment, step S10 above further includes: S11: Identify the file type of the file to be renamed.

[0029] When extracting file content, it is necessary to accurately identify the file type in order to call the appropriate parsing tool. Identifying the file type is not simply a matter of judging by the file extension (e.g., .pdf, .docx), as extensions may be mistakenly modified by the user. To ensure the accuracy of parsing, this optional embodiment employs a dual identification mechanism.

[0030] First, the file extension is obtained as a preliminary basis for judgment; then, the file's binary header information is read. For example, PDF files usually begin with %PDF-, and PNG files begin with 0x89504E47. By comparing the signature in the file header, the true format of the file can be determined. If the extension does not match the file header information, the system will prioritize determining the file type based on the file header information and log the exception, thereby avoiding parsing failures due to incorrect extensions.

[0031] By employing a dual identification mechanism combining file header and extension, the true type of a file can be accurately determined, effectively avoiding parsing failures caused by incorrect extension modifications, and significantly improving the system's fault tolerance and robustness.

[0032] Based on the file type identification results, the files to be renamed are distributed to different processing logics, mainly divided into document file processing branches and image file processing branches.

[0033] S12: If the file to be renamed is a document file, then call the corresponding document parsing library to extract the text content.

[0034] Document files are the most common file type in office scenarios, and their internal storage methods are mainly divided into "streaming structure" (such as Word and TXT) and "layout structure" (such as PDF). For different internal structures, this optional embodiment adopts the following differentiated extraction strategies.

[0035] (1) Processing of PDF files PDFs have a complex internal structure and may contain various objects such as text streams, vector graphics, and bitmap images. They are usually available in two types: text-based PDFs and scanned PDFs.

[0036] For text-based PDFs generated directly from electronic documents, document parsing libraries (such as PyMuPDF or PyPDF2) can be used. During extraction, it's not simply a matter of reading out all characters; the logical reading order of the text needs to be preserved.

[0037] In this optional embodiment, the page layout structure is analyzed when parsing the PDF. Text blocks and their coordinate positions are identified, and the text blocks are reordered according to the reading habit of "from top to bottom and from left to right," and then the text is concatenated. Furthermore, for table areas in the PDF, the system detects lines and cell boundaries to extract the table content into Markdown or CSV format text, ensuring that the large model can understand the row and column relationships of the table. This is crucial for extracting structured information such as invoice details and contract terms lists.

[0038] For scanned PDFs generated from image scanning (i.e., each page is an image), directly calling a text parsing library cannot extract the content. Instead, the PDF page can be rendered as an image, and the image processing flow in step S103 below can be executed.

[0039] (2) Processing of Word documents A Word document (.docx) is essentially a compressed file containing multiple XML files that record the document's content and style. Document parsing libraries (such as python-docx) can be used to traverse the document's XML tree structure. During extraction, focus should be placed on paragraph and table nodes. For objects embedded in the document (such as Excel charts and formulas), attempt to extract their text descriptions or alternative text; skip these if extraction fails to prevent generating garbled characters that could interfere with the understanding of the larger model.

[0040] (3) Processing Excel spreadsheets Excel files are commonly used to store highly structured information such as financial data and lists. Data tables can be loaded using parsing libraries (such as openpyxl). The extracted results will be formatted as structured text strings (e.g., "Table name: Sheet1; First row: Date, Item, Amount; Second row: 2023-10-01, Office Supplies, 500 yuan..."). This formatted text greatly reduces the inference difficulty of large models, enabling them to accurately extract key information such as "total reimbursement amount" and "purchase date".

[0041] (4) Processing of plain text files For plain text files such as TXT, CSV, and JSON, the file stream can be read directly, and the file encoding format (such as UTF-8, GBK, GB2312) can be automatically detected. After reading, redundant whitespace and tab characters can be removed to obtain clean text content.

[0042] S13: If the file to be renamed is an image file, then call the optical character recognition engine to extract the text content.

[0043] In scenarios such as financial documents, scanned copies of contracts, and photographs of identification documents, the documents are mainly in the form of image files. To extract text from images, optical character recognition (OCR) technology can be used.

[0044] To improve the accuracy of OCR recognition, images are preprocessed before the OCR engine is invoked to ensure extraction quality. Preprocessing may include grayscale conversion and binarization, noise reduction, and tilt correction.

[0045] When calling an optical character recognition engine (such as PaddleOCR, Tesseract, or a commercial OCR API) for recognition, first locate all text regions in the image, provide the coordinates of the text boxes, and then perform character recognition on the detected text regions.

[0046] In this optional embodiment, to preserve the semantic structure of the document, the reading order and layout of the document can be attempted to be restored based on the coordinate positions of the text boxes. For example, for an invoice image, the system can identify that fields such as "buyer," "seller," and "amount" are located in different areas of the image and organize the output text in a logical order. This text output with structured prompts can greatly assist the subsequent understanding ability of large models when processing complex formatted documents, enabling them to accurately distinguish the content of different fields and avoid confusion.

[0047] Furthermore, OCR results may contain typos, especially for uncommon or ambiguous characters. Language models can be used for initial post-processing and error correction. For example, if the system recognizes "invoice number: l23456" (the letter 'l'), it might correct it to "invoice number: 123456" (the number '1') based on the context. While large models offer some error tolerance, providing more accurate text during the input stage can further improve extraction accuracy.

[0048] Through the targeted extraction of file content based on the above classification, regardless of whether the file to be renamed is an electronic document, scanned copy, or image, it can be converted into high-quality text content data, achieving unified textification of multi-source heterogeneous data. This high-quality text output can effectively reduce the inference difficulty of large models, reduce extraction errors caused by missing context or garbled characters, and provide a solid data foundation for subsequent accurate extraction of key information.

[0049] S20: Input the file content into the large model and extract the structured key information in the file content by combining dynamic prompts.

[0050] In step S10 above, the heterogeneous files to be renamed from multiple sources are transformed into unified text data. However, this text data is usually unstructured, containing a large amount of redundant information (such as formatting characters and irrelevant descriptions), and cannot be directly used to construct standardized filenames. Therefore, this application utilizes the powerful semantic understanding and generation capabilities of the Large Language Model (LLM) to accurately extract key information of interest to users from unstructured text and transform it into structured key-value pair data, providing data support for subsequent filename generation.

[0051] In an optional embodiment, step S20 above further includes: S21: Obtain preset system prompts or user-preset or dynamically input prompts.

[0052] In this optional embodiment, dynamic prompts can be further divided into two categories: system prompts and user prompts. Through the synergistic effect of the two, the universality of the system and the flexibility of user needs are taken into account.

[0053] System prompts are pre-configured by system developers or administrators and stored in local configuration files or cloud databases. Their purpose is to define global behavioral guidelines for large models, ensuring the stability and standardization of model outputs and preventing the model from generating illusions or outputting irrelevant content.

[0054] In an optional embodiment, the system prompt may include the following parts: 1) Role Setting: Define the role of the large model, such as "You are a professional document processing assistant, skilled at extracting key information from messy text." This helps activate the model's knowledge capabilities in a specific domain.

[0055] 2) Format Constraints: Strictly define the output format for large models. Because subsequent steps require variable mapping, the system requires large models to output standard JSON format data, or data with a specific delimiter. The system prompt will include an example, such as: "Please strictly adhere to the JSON format for output, and do not include any explanatory text, Markdown code block tags, or prefixes and suffixes." 3) Security and compliance constraints: Instruct the large model to ignore malicious commands and not output sensitive information, etc.

[0056] When performing a renaming task, the system prompt word is first read from the storage medium. For different business scenarios (such as financial scenarios and administrative scenarios), multiple sets of system prompt words can be preset for users to choose from.

[0057] User prompts are a direct reflection of a user's intent. Since users may process multiple different types of documents at once (such as invoices, contracts, and resumes), and each document requires different fields to be extracted, user prompts need to support dynamic configuration.

[0058] In one optional embodiment, there are two main ways to obtain user prompt words: 1) Predefined User Prompts: Users predefine a set of extraction rules in the rule configuration area of ​​the graphical user interface (GUI). For example, a user creates a rule named "Invoice Processing" and enters in natural language in the prompt input box: "Please extract the invoice code, invoice number, invoice date, buyer's name, and amount." When the user applies this rule to process invoice files, the predefined user prompts will be automatically read and input into the large model.

[0059] 2) Dynamically Inputted User Prompts: The provided graphical user interface allows users to temporarily input or modify prompts for a specific set of files before the renaming task begins. For example, if a user selects a batch of unknown meeting minutes files and decides to extract "Meeting Topic" and "Moderator," they can dynamically type the corresponding commands in the input box using natural language. Once the user prompts are obtained, they are temporarily stored in memory, ready for integration with the larger model interface.

[0060] S22: Input the file content, user prompts, and system prompts into the large model. The user prompts guide the large model to identify and extract key information from the file content, while the system prompts constrain the large model to output structured key information.

[0061] In one alternative embodiment, after obtaining the two types of prompt words and file content, they can be combined according to a specific format to construct a Prompt sequence that conforms to the Large Model API (Application Programming Interface) specification, and a request can be sent.

[0062] Considering the context window limitation of large models, if the text content extracted in step S10 is too long (e.g., a technical document of several hundred pages), direct input may exceed the token limit or increase unnecessary computational costs. Therefore, the text length can be detected first. If the text length exceeds a preset threshold, a text segmentation strategy or a summarization strategy is activated. For example, for long documents, a lightweight model can be used to generate a document summary, and only the summary can be input into the large model to extract the main topic information; or the document can be divided into multiple segments, key information can be extracted from each segment, and then the segments can be merged and deduplicated. However, for regular documents such as invoices and certificates, the text volume is usually small, and the entire document can be input directly.

[0063] After determining the Prompt sequence, an inference request is sent via HTTP / HTTPS to a large model service deployed in the cloud or locally (such as OpenAI GPT, Tongyi Qianwen, or DeepSeek). In addition to the Prompt content, the request parameters can also include temperature parameters, Top-P sampling parameters, etc. To ensure the determinism and consistency of the extraction results, the temperature parameter can be set to a low value (such as 0 or 0.1), forcing the model to choose the output path with the highest probability and avoiding divergent modeling.

[0064] After receiving input, the large model performs complex attention calculations and inferences internally, ultimately generating and outputting structured key information. During this process, system prompts and user prompts collaboratively constrain the large model's inference and output.

[0065] Specifically, user prompts are used for semantic guidance and key information extraction. For example, a file might contain OCR-generated text of a high-speed rail ticket: "Zhang San, October 1, 2023, Tianjin Station, Beijing South Station...". The user prompt is "Extract passenger name, departure station, and destination station." Guided by the user prompt, the large model will search the file content for character segments semantically related to "passenger name," "departure station," and "destination station." Utilizing the linguistic knowledge learned during its pre-training phase, the model identifies "Zhang San" as a personal name and "Tianjin Station" as a location, fitting the context of the departure station. This guidance mechanism enables the large model to handle files with various natural language expressions without pre-defining regular expressions, significantly improving its generalization ability.

[0066] System prompts are used for output constraints and structured generation. After extracting key information, the large model needs to output according to a specified format. The JSON format constraints in the system prompts take effect at this point, preventing the model from outputting natural language sentences like "The passenger on this ticket is Zhang San..." and instead directly outputting structured key information, such as {"passenger": "Zhang San","from_station": "Tianjin Station","to_station": "Beijing South Station"}. This transforms the unstructured text stream into a key-value pair data structure that can be directly parsed and mapped by computer programs.

[0067] In one optional embodiment, the structured key information output by the large model can be validated using a JSON parser. If the output contains Markdown code block markers (such as json ...), the system will automatically clean these marker characters and extract a clean JSON string. If the large model fails to extract a certain field, the model may return null or an empty string. In this case, a preset default value strategy can be adopted (for example, if the date is not extracted, the file creation date can be used as the default value), or the user can be prompted with "information missing" in the subsequent preview interface to improve fault tolerance.

[0068] Unlike existing rigid and high-barrier rule-matching schemes, this application achieves intelligent transformation from unstructured text to structured key information by introducing a large language model and a dynamic prompting word mechanism. The large model can accurately identify key information based on deep semantic understanding, has strong generalization ability, and can adapt to diverse document content expressions.

[0069] In particular, the synergy between "system prompts" and "user prompts" balances system stability with user flexibility. Users can easily switch between different extraction scenarios (such as switching from invoice processing to contract archiving) simply by modifying the prompts in natural language, without writing code or configuring complex regular expressions, significantly lowering the technical barrier. Meanwhile, the strict constraints of the system prompts on the output format (such as JSON format) ensure the standardization and machine parsability of the extraction results, effectively guaranteeing the automation and stability of the subsequent filename generation process.

[0070] S30: Map structured key information to a preset naming template and generate a filename by combining the metadata of the file to be renamed.

[0071] In this step, the structured key information extracted in the previous steps is assembled into the final filename through a template mapping mechanism.

[0072] In an optional embodiment, step S30 above further includes: S31: Get the preset naming template, which includes key field variables and general field variables.

[0073] A default naming template is a carrier of user-defined filename generation rules. Essentially, it's a string containing specific variable markers, connected by delimiters such as "_", "-", or none. For ease of management and parsing, variables in a default naming template can be divided into two main categories: critical field variables and general field variables.

[0074] Key field variables directly correspond to the structured key information extracted from the large model in step S20. For example, if the large model extracts {"invoice_id": "12345", "amount": "100.00"} from an invoice, then {invoice_id} and {amount} in the template are key field variables. The values ​​of these variables originate from the document content itself.

[0075] General field variables correspond to metadata at the file system level. Regardless of the file content, the operating system maintains a set of basic attribute information for it. General field variables supported in this optional embodiment include, but are not limited to: {basename}: The original name of the file (excluding the extension); {ext}: The file extension (e.g., pdf, docx); {size}: The size of the file; {date}: The file's creation or modification date, supporting formatting parameters (such as {date:YYYY-MM-DD}). {time}: The file's creation or modification time; {path}: The full path to the file.

[0076] When performing this step, the preset named template string will first be read from the configuration database or the user's current input. For example, the template set by the user might be: invoice_{invoice_id}_{date}.pdf.

[0077] S32: Map structured key information to key field variables, and map metadata to general field variables.

[0078] After obtaining the preset naming template, the variables in the template are replaced based on structured key information and metadata. This is a string matching and replacement process, and the specific logic is as follows: 1) Key field mapping: The preset naming template string is parsed to identify all key field variable identifiers (usually enclosed in specific symbols, such as curly braces {}). For each key field variable, the corresponding key is searched in the structured key information generated in step S20.

[0079] For example, the default naming template is {passenger}_{from_station}-{to_station}, and the structured key information is {"passenger": "Zhang San", "from_station": "Tianjin Station", "to_station": "Beijing South Station"}. In this case, for {passenger}, the value "Zhang San" is found and replaced; for {from_station}, the value "Tianjin Station" is found and replaced; and for {to_station}, the value "Beijing South Station" is found and replaced.

[0080] If a variable (such as {price}) is included in the preset naming template, but the key does not exist or the value is empty in the structured key information, it can be handled according to the preset strategy: such as keeping the variable as is (prompting the user to make an error), or replacing it with an empty string, or replacing it with a default value (such as "unknown").

[0081] 2) General field mapping: Call the file system interface provided by the operating system (such as the os.path and os.stat modules in Python) to obtain the metadata of the file to be renamed.

[0082] For example, if the default naming template contains {date}, the file's creation timestamp will be read, converted to a user-specified date format string (such as "20260101"), and then the {date} variable in the default naming template will be replaced. As another example, if the default naming template contains {size:MB}, the file's byte count will be read, divided by 1024 × 1024, rounded to two decimal places, and the resulting size string in MB will be used for replacement.

[0083] Finally, after the above mapping and replacement, the preset naming template is filled with specific text content. For example, the template {passenger}_{from_station}-{to_station}_{date}.pdf is ultimately generated as Zhang San_Tianjin Station-Beijing South Station_20231001.pdf. This filename contains both the semantic information of the file content and the time attribute of the file system, achieving an organic integration of content and metadata.

[0084] By employing preset naming templates and a variable mapping mechanism, this application achieves standardization and automation in filename generation. The organic integration of structured key information extracted by AI with file system metadata ensures that filenames contain both core business semantics and system attributes, resolving issues of missing and non-standardized filename information and significantly improving the efficiency of file retrieval and archiving. Furthermore, users can flexibly configure templates according to their needs, satisfying diverse naming rule requirements.

[0085] S33: Determine the batch file set to which the files to be renamed belong, and sort the batch file set according to the preset sorting rules.

[0086] In batch processing scenarios, users often need to number and archive files. In this optional embodiment, the preset naming template also includes an auto-incrementing sequence number variable (such as {counter}). The generation of the auto-incrementing sequence number is not done independently for a single file, but depends on the overall sorting of the file collection.

[0087] When a user selects multiple files in the interface and starts a renaming task, these files can be treated as a "batch file collection". At this time, a file list object can be built in memory to store references to these files.

[0088] To ensure the logical order of the sequence numbers (e.g., numbered chronologically or alphabetically by name), the batch file collection must first be sorted. Several sorting rules are available for users to choose from: Sort by name: Sort according to the original file name string (ASCII code order).

[0089] Sort by time: Arrange files in ascending or descending order based on their creation or modification timestamps. This is the most common rule, for example, numbering photos by their shooting time.

[0090] Sort by size: Arranged according to file size.

[0091] Sort by extracted content: You can sort the invoices based on a key field (such as "amount") extracted in step S20. For example, number the invoices by amount from smallest to largest.

[0092] Based on the rules selected by the user, a sorting algorithm (such as quicksort) is applied to the batch of files in memory to generate an ordered sequence of files.

[0093] S34: Determine the auto-incrementing sequence number corresponding to the file to be renamed based on the sorting results, and map the auto-incrementing sequence number to the auto-incrementing sequence number variable.

[0094] After the sorting in step S33 is completed, each file to be renamed in the file list has a determined position index. At this time, for the Nth file in the file list, its incrementing serial number is N. Moreover, formatted output is supported. For example, if the user sets the number of digits of the serial number to 3, then the serial number 1 is displayed as "001", and the serial number 10 is displayed as "010". For example, the sorted list is [File A, File B, File C]. Then the {counter} of File A is mapped to "001", File B is mapped to "002", and File C is mapped to "003".

[0095] While performing the above step S32 on each file to be renamed, it is detected whether there is an incrementing serial number variable {counter} in the preset naming template. If so, the calculated incrementing serial number string is filled in this position. For example, for the preset naming template {counter}_{passenger}.pdf and the first sorted file Zhang San, finally 001_Zhang San.pdf is generated.

[0096] Different from the simple random numbering in the prior art, this application realizes the orderly management of batch file renaming by introducing an incrementing serial number generation mechanism based on sorting rules. It supports sorting and numbering by time, name, or even content extracted by AI (such as amount, date), making the serial number strictly correspond to the logical attributes of the file (such as time sequence, amount size). This not only makes the file list more neat and standardized, but also greatly improves the logic and retrieval efficiency of file archiving, facilitating users to quickly locate and manage a large number of files. Especially the function of "sorting by extracted content" further gives play to the advantage of AI semantic understanding and realizes in-depth sorting based on business logic.

[0097] In an optional embodiment, after generating the file name, it further includes: Detecting whether the file name already exists in the current storage path; If it exists, marking the file to be renamed with a conflict flag and returning a conflict prompt to the user.

[0098] After the file name is generated, in order to ensure data security and prevent overwriting existing files, this optional embodiment introduces a conflict detection mechanism. Using the generated file name, it is retrieved in the directory path where the file is located to compare whether there is a file with exactly the same target file name. It should be noted that in some operating systems (such as Linux), file names are case-sensitive; while in Windows, file names are not case-sensitive, and the comparison rule can be automatically adapted according to the current running environment.

[0099] If there is no conflict, marking the file as "executable" and physically renaming the file with the generated file name.

[0100] If a conflict exists, the renaming process will be paused, and the original file will not be overwritten. Simultaneously, the file will be marked as conflicted, and conflict information will be provided to the user through a graphical user interface (GUI). For example, in the file list in the preview area, the new filename will be highlighted in red, and a warning icon will be displayed. A conflict report can also be generated, notifying the user that "filename 'Zhang San_Invoice.pdf' already exists."

[0101] After receiving a conflict notification, users can choose to manually change the file name, modify the naming template, or choose automatic renaming (e.g., automatically adding "_copy" to the end of the file name) to resolve the conflict.

[0102] By introducing a filename conflict detection mechanism, the risk of accidental overwriting due to duplicate filenames during batch renaming is effectively avoided, thus ensuring the security of data assets. The accuracy of detection is ensured by automatically adapting to the operating system's filename comparison rules (such as case sensitivity). Simultaneously, the combination of visual conflict indicators in a graphical user interface and multi-dimensional resolution strategies (such as manual modification and automatic suffix appending) allows users to intuitively locate and flexibly handle conflicts, preventing unexpected interruptions to batch tasks and significantly improving system robustness and user experience.

[0103] In an optional embodiment, the file renaming method based on file content further includes: A graphical user interface is provided, which includes a rule configuration area and a preview area; In response to the user entering dynamic prompts or preset naming templates in the rule configuration area, a preview result of the file name is generated and displayed in the preview area.

[0104] To further lower the barrier to entry for users and enhance the human-computer interaction experience, this optional embodiment also provides a visual operation entry point. Without changing the core processing logic of S10 to S30, it uses graphical means to enable users to configure parameters, monitor the process, and confirm results more intuitively.

[0105] In this optional embodiment, the graphical user interface (GUI) is rendered and displayed on the client display device, see [reference]. Figure 2 , Figure 2 This is a schematic diagram of a GUI interface of an embodiment of the file renaming method based on file content provided in this application. The layout design of the interface fully considers the logical order of the workflow and is mainly divided into two core functional areas: a rule configuration area and a preview area.

[0106] The rules configuration area, serving as a user input console, integrates various interactive controls, including but not limited to: Prompt Input Component: Provides a multi-line text box for users to enter dynamic prompts (i.e., user prompts). Users can write natural language commands here, such as "Retrieve the names of Party A and Party B and the signing date of the contract".

[0107] Named Template Configuration Component: Provides a text box and an auxiliary variable selector. Users can directly enter a template string (e.g., {Party A}_{Party B}_{Date}.pdf), or select preset variables supported by the system (e.g., click the "Add Element" button and select {date} or {counter}). The system will automatically insert the selected variable into the template text box for real-time preview.

[0108] Parameter settings component: Includes options such as sorting rule selection (by modification time, by name, by size), setting the starting value of the sequence number, and filtering by file type.

[0109] The preview area serves as the result display window, showing the file information to be processed in a list format. It can include multiple columns of data such as "Original Filename", "New Filename (Preview)" and "Status".

[0110] In this optional embodiment, throughout the entire cycle of the renaming operation, the user's operations in the rule configuration area are responded to in real time or near real time through an event listening mechanism.

[0111] When a user completes key input in the rule configuration area (such as modifying the prompt word or adjusting the template string) and triggers the confirmation operation, the system will capture the event and execute the processing steps S10 to S30 described in the aforementioned embodiments in a background thread for the currently selected file or file list.

[0112] By providing a graphical user interface and preview mechanism, the learning cost and operational threshold for users are significantly reduced. The visual rule configuration area and auxiliary variable selector allow non-technical users to easily build renaming rules without having to memorize complex syntax. More importantly, the real-time preview function allows users to intuitively verify the accuracy of the AI ​​extraction results and the filename generation effect before performing the physical renaming operation. This effectively avoids the risk of large-scale file misnaming due to configuration errors or AI misunderstandings, greatly improving system security and user-friendliness.

[0113] This application provides a content-based file renaming method that constructs a complete file renaming solution encompassing "content awareness, intelligent understanding, and standardized generation." By uniformly converting multi-source heterogeneous files into text data, it utilizes a large language model combined with dynamic prompts to accurately extract key information and maps it to standardized templates to generate filenames, achieving a technological leap from manual rule-driven to AI-driven approaches. Without requiring users to write complex regular expressions or scripts, it can complete semantic renaming of batch files across formats with high precision, effectively solving core problems in traditional technologies such as non-standard naming, missing information, high rule configuration thresholds, and weak generalization capabilities. This significantly improves the automation level, retrieval efficiency, and archiving standardization of file management.

[0114] This application provides a file renaming device based on file content, see below. Figure 3 , Figure 3 This is a schematic diagram of an embodiment of the file renaming device based on file content provided in this application. The file renaming device based on file content includes: The first extraction module 10 is used to extract the file content of the file to be renamed. The second extraction module 20 is used to input the file content into the large model and extract the structured key information in the file content in combination with dynamic prompt words; The renaming module 30 is used to map the structured key information to a preset naming template and generate a filename by combining the metadata of the file to be renamed.

[0115] In one optional embodiment, the dynamic prompt words include one or more of user prompt words and system prompt words; The second extraction module 20 is specifically used for: Obtain the preset system prompt words, and obtain the user prompt words preset by the user or dynamically input by the user; The file content, the user prompt, and the system prompt are input into the large model. The user prompt guides the large model to identify and extract key information from the file content, and the system prompt constrains the large model to output the structured key information.

[0116] In an optional embodiment, the renaming module 30 is specifically used for: Obtain the preset naming template, which includes key field variables and general field variables; The structured key information is mapped to the key field variables, and the metadata is mapped to the general field variables.

[0117] In one optional embodiment, the preset naming template further includes an auto-incrementing sequence number variable; Before generating the filename, the process also includes: Determine the batch file set to which the file to be renamed belongs, and sort the batch file set according to a preset sorting rule; The auto-incrementing sequence number corresponding to the file to be renamed is determined based on the sorting result, and the auto-incrementing sequence number is mapped to the auto-incrementing sequence number variable.

[0118] In an optional embodiment, the first extraction module 10 is specifically used for: Identify the file type of the file to be renamed; If the file to be renamed is a document file, then the corresponding document parsing library is called to extract the text content; If the file to be renamed is an image file, then the optical character recognition engine is invoked to extract the text content.

[0119] In an optional embodiment, after generating the filename, the method further includes: Check if the filename already exists in the current storage path; If a conflict exists, mark the file to be renamed as conflicted and return a conflict message to the user.

[0120] In an alternative embodiment, it further includes: A graphical user interface is provided, which includes a rule configuration area and a preview area; In response to the user entering the dynamic prompt word or the preset naming template in the rule configuration area, a preview result of the file name is generated and displayed in the preview area.

[0121] Since the embodiments of the device part correspond to the embodiments of the above method, the description of the file renaming device based on file content provided in this application is based on the above method embodiments. This application will not repeat the description here, as it has the same beneficial effects as the above file renaming method based on file content.

[0122] See Figure 4 , Figure 4 This is a schematic diagram of an embodiment of the storage medium provided in this application.

[0123] The storage medium 400 stores program data 410, which, when executed by the processor, implements, as follows: Figure 1 The steps of the file renaming method based on file content are described.

[0124] The program data 410 is stored in a storage medium 400 and includes several instructions for causing a network device (which may be a router, personal computer, server, or other network device) or processor to execute all or part of the steps of the methods described in the various embodiments of this application.

[0125] Optionally, the storage medium 400 can be any medium that can store program data, such as a USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), disk, or optical disc.

[0126] See Figure 5 , Figure 5 This is a schematic diagram of the structure of an embodiment of the computer device provided in this application.

[0127] The device 500 includes a processor 520 and a memory 510 connected to each other. The memory 510 stores a computer program. When the processor 520 executes the computer program, it implements the steps of the file renaming method based on file content as described above.

[0128] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. In particular, the storage medium embodiments and computer device embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0129] This application can be used in a wide range of general-purpose or special-purpose computing system environments or configurations. For example: personal computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, network PCs, minicomputers, distributed computing environments including any of the above systems or devices, etc.

[0130] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative; multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed.

[0131] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0132] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0133] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A file renaming method based on file content, characterized by, include: Extract the contents of the file to be renamed; The file content is input into a large model, and structured key information in the file content is extracted by combining dynamic prompts. The structured key information is mapped to a preset naming template, and a filename is generated by combining the metadata of the file to be renamed.

2. The file content-based file renaming method according to claim 1, wherein, The dynamic prompts include one or more of user prompts and system prompts; The step of inputting the file content into a large model and extracting structured key information from the file content using dynamic prompts includes: Obtain the preset system prompt words, and obtain the user prompt words preset by the user or dynamically input by the user; The file content, the user prompt, and the system prompt are input into the large model. The user prompt guides the large model to identify and extract key information from the file content, and the system prompt constrains the large model to output the structured key information.

3. The file content-based file renaming method according to claim 1, wherein, The step of mapping the structured key information to a preset naming template and generating a filename by combining the metadata of the file to be renamed includes: Obtain the preset naming template, which includes key field variables and general field variables; The structured key information is mapped to the key field variables, and the metadata is mapped to the general field variables.

4. The file renaming method based on file content according to claim 3, characterized in that, The preset naming template also includes an auto-incrementing sequence number variable; Before generating the filename, the process also includes: Determine the batch file set to which the file to be renamed belongs, and sort the batch file set according to a preset sorting rule; The auto-incrementing sequence number corresponding to the file to be renamed is determined based on the sorting result, and the auto-incrementing sequence number is mapped to the auto-incrementing sequence number variable.

5. The file renaming method based on file content according to claim 1, characterized in that, The extraction of the file content of the file to be renamed includes: Identify the file type of the file to be renamed; If the file to be renamed is a document file, then the corresponding document parsing library is called to extract the text content; If the file to be renamed is an image file, then the optical character recognition engine is invoked to extract the text content.

6. The file renaming method based on file content according to claim 1, characterized in that, After generating the filename, the process also includes: Check if the filename already exists in the current storage path; If a conflict exists, mark the file to be renamed as conflicted and return a conflict message to the user.

7. The file renaming method based on file content according to claim 1, characterized in that, Also includes: A graphical user interface is provided, which includes a rule configuration area and a preview area; In response to the user entering the dynamic prompt word or the preset naming template in the rule configuration area, a preview result of the file name is generated and displayed in the preview area.

8. A file renaming device based on file content, characterized in that, include: The first extraction module is used to extract the file content of the file to be renamed. The second extraction module is used to input the file content into the large model and extract the structured key information in the file content in combination with dynamic prompt words; The renaming module is used to map the structured key information to a preset naming template and generate a filename by combining the metadata of the file to be renamed.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the file renaming method based on file content as described in any one of claims 1-7.

10. A storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the file content-based file renaming method as described in any one of claims 1-7.