When the filenames of multiple text files lack meaningful descriptions but the file content includes Book IDs, serial numbers, or numeric IDs, you can use the file content to batch rename them. This article uses HeSoft Doc Batch Tool to demonstrate the complete process: Go to the "Rename Text Files Using File Content" option under the File Name Classification, add the TXT files, select the text matched by a custom formula in the processing options, and enter the regular expression (?
In the process of organizing documents, whether file names are clear directly affects the efficiency of subsequent searches. Many TXT text files use default names or sequential names when generated, such as book1.txt, book2.txt. Although the files themselves already contain a Book ID or other unique identifier, this information is not visible in the folder, making it necessary to open and check each one individually when searching.
If you are dealing with dozens or even thousands of text files, manually opening, copying the ID, and pasting to rename is extremely inefficient. More troublesome is that if a single digit is copied incorrectly, the file name and its content will no longer match. This article introduces a method more suitable for office batch processing: using HeSoft Doc Batch Tool to extract numeric IDs from file content using wildcards/regex, and batch rename multiple TXT files to these IDs.
Applicable Scenario: Fixed fields in file content, file names need standardization
This method is suitable for all text file organization tasks where "the main body has an extractable field, and the file name needs to be uniformly named according to this field." In the example, the first line of the file content contains Book ID:4829173056, and the goal is to change the file name to 4829173056.txt. Similar scenarios include: naming log files by device number, naming order texts by order number, naming material files by customer number, and naming article export files by manuscript ID.
The prerequisite for this batch processing method is that each file has a relatively stable text format. For instance, they all contain "Book ID:" followed by a number, or all contain "Number:" followed by a string. The more uniform the format, the easier it is to write the regex, and the more stable the batch processing result will be.
HeSoft Doc Batch Tool is a software for batch processing office files, with its interface organizing functions into categories such as File Name, Folder Name, Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, and Text Tools. Its value lies in reducing repetitive work, turning file operations that require manual handling one by one into batch execution. This article focuses on using the text file content renaming function within the File Name category.
Result Preview: Before and After Batch Renaming
Before Processing: File names cannot directly reflect the main content
Before processing, the folder contains five files: book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. These names only indicate their sequence, not the corresponding Book ID. To find a specific number, one must open them one by one.

After opening one of the text files, you can see Book ID:4829173056 on the first line. The number 4829173056, highlighted by the red arrow, is exactly the content we want to extract as the file name. The English title and body paragraphs that follow do not need to be included in the name.

After Processing: File names automatically become numeric IDs from the main content
After the batch processing is complete, the file names displayed in the folder have become 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt. Each file name corresponds to the Book ID in its text content.

This naming convention is better suited for archiving and retrieval. For example, if you see Book ID 4829173056 in a spreadsheet or system, you can directly locate 4829173056.txt without guessing whether it was originally book1 or book2.
Operation Steps: From Importing Files to Regex Matching
Step 1: Open the Text File Content Renaming Function
Open HeSoft Doc Batch Tool , and select "File Name" in the left navigation. In the right function area, find and enter Rename Text Files Using File Content. In the screenshot, this function is located in the file name tool list and is marked by an arrow.

The purpose of this step is to enter the processing wizard specifically designed for renaming TXT files by content. Do not choose the generic "Find and Replace Keywords in File Names," as this example does not involve modifying a section of text in the original file name but extracting content from the file body to serve as the new file name.
Step 2: Add or Import the Text Files to be Renamed
After entering this function, the page displays Step 1, "Select records to be processed." You can choose specific TXT files via "Add Files" or import files from a directory all at once using "Import Files from Folder". In the example, 5 text files from D:\test have already been imported.

After import, the list will show each file's name, path, extension, and timestamp. Here, you should specifically confirm that the extension is txt, the path is the target directory, and the number of records matches expectations. Batch processing is highly efficient but requires accurate preliminary selection; otherwise, files that should not be renamed may be added to the task.
After checking, click "Next" at the bottom. At this point, the software will enter the processing option settings interface, which is used to define which part of the text content to extract as the file name.
Step 3: Choose to Match Text Using a Custom Formula
In the "Set processing options" interface, you will first see the "Search area." The screenshot shows options like "First line of text" and "Text matched by a custom formula." Here, you should select Text matched by a custom formula.

The reason for selecting this option is: we only want the number after Book ID, not the entire line. If we directly take the first line, it might include the "Book ID:" label; using a custom match allows us to write a more precise rule, extracting only the numeric ID.
Step 4: Use (?<=Book ID:)\d+ to Extract the Number After the Colon
Enter the following in the regular expression input box:
(?<=Book ID:)\d+
This expression is the core of this batch renaming task. It means: find a string of digits immediately preceded by "Book ID:". For text like Book ID:4829173056, the match result is 4829173056.
From a rule structure perspective, (?<=Book ID:) is used to assert that the text before the number must be "Book ID:", while \d+ is used to match consecutive digits. This allows us to avoid matching other numbers in the body text and prevents the descriptive text "Book ID:" from being brought into the file name.
If your actual files contain "Book ID: 4829173056" with an extra space, the rule may need adjustment based on the actual situation. The example in this article strictly corresponds to the format in the screenshot, where a number directly follows "Book ID:" without a space.
Step 5: Overwrite the Original File Name with the Match Result
In the "Position" area, select Overwrite the entire file name. This setting means completely replacing the original file name's main body with the matched text. For example, if 4829173056 is matched in book2.txt, after processing it will become 4829173056.txt.
If you choose to insert on the left or right, the result might retain "book2" and append the number; however, this example's goal is for the file name to contain only the Book ID, making "Overwrite the entire file name" the appropriate choice. This ensures the processed file list is more uniform and easier to correspond with an external ID manifest.
Step 6: Follow the Wizard to Complete the Save Location and Start Processing
After setting the regex and position, continue by clicking "Next." The interface flow shows subsequent steps for "Set save location" and "Start processing." Once the save location is confirmed according to actual needs, you can execute the batch process.
During processing, the software will read the content of each TXT file according to the import list, use the regex to find the number after "Book ID:", and then rename the file with that number. After processing is complete, go back to the folder to view the results, and you will see that files like book1.txt have been renamed to numeric ID names.
Key Points for Using Regular Expressions: Extract Stable Fields, Don't Extract Entire Paragraphs of Text
In batch renaming, the goal of the regex is not complexity, but a close fit to the file content. The file format in this article is very clear: "Book ID:" is followed by a string of numbers. Therefore, simply using (?<=Book ID:)\d+ can complete the extraction.
If you want to extract a Chinese identifier, you can replace "Book ID:" with the actual Chinese field; if you want to extract a combination of letters and numbers, you need to change the part that only matches digits to a rule suitable for alphanumeric characters. In any case, it is recommended to start testing with a small number of samples to confirm that the match result is exactly what you want as the file name.
It's important to note that file names should not contain overly long text or special symbols. In the example, a pure numeric ID was extracted, which is of moderate length and has no illegal characters, making it very suitable for file naming. If extracting titles, sentences, or content with punctuation, special attention should be paid to file name legality and readability.
Frequently Asked Questions and Notes
1. Why check the file content before processing?
Because the regex must be written according to the file content format. In the screenshot, the Book ID format is Book ID:4829173056, so a rule using a fixed prefix followed by digits can be used. If the format is inconsistent across different files, the batch result may be unstable.
2. Does it only process .txt files?
This article demonstrates processing for TXT text files. In the HeSoft Doc Batch Tool interface, you can also see entry points for related content renaming for Word, PDF, and other file types. If processing .doc, .docx, or PDF files, you should select the corresponding function, not the text file entry point used in this article.
3. Can I use a title as the file name?
If the title's position in the file is fixed, extracting the title could also be considered. However, titles often include spaces, punctuation, or long text, requiring more caution when naming. This article chose the Book ID because a numeric ID is short, unique, and easy to search.
4. Is it easy to make mistakes with batch processing?
Batch processing itself can reduce human errors, but the premise is that the rules are correct. It is recommended to first test with 2 to 5 files, confirm that the file names after processing are as expected, and then expand to the full folder. It is advisable to back up important data first.
5. What if duplicate IDs are extracted?
Duplicate IDs can lead to potential file name conflicts. Before batch processing, try to confirm the uniqueness of the Book IDs. If the business allows for duplicate numbers, consider appending other information to the number, but the example in this article uses the ID to overwrite the entire file name.
Summary: Using Content to Name Files Makes Organization Work More Efficient
Using file content to batch rename multiple text files allows the heavy, repetitive work of manual renaming to be handled by software. The example in this article uses HeSoft Doc Batch Tool to import book1.txt through book5.txt, uses (?<=Book ID:)\d+ to extract the numeric ID from the file body, selects "Overwrite the entire file name," and finally obtains a set of TXT files named after their Book IDs.
This method is especially suitable for scenarios like office document archiving, organizing text records, and managing numbered files. Compared to manual renaming, batch processing is faster, more consistent in its rules, and less prone to omissions. It is recommended that you first identify a stable field based on your own file content, then set up the regex for a small-batch test, and once it is error-free, proceed to batch process all files.