When a large number of TXT text files are still saved with temporary names like book1.txt, book2.txt, manually opening each one, copying the number, and then renaming it is very time-consuming. This article describes how to use HeSoft Doc Batch Tool to batch rename TXT files based on specified text within the file content, such as extracting the number after "Book ID" in the first line of each file and using it as the new file name. By adding files, setting regular expression matching rules, choosing to overwrite file names, and executing the process, you can rename multiple text files at once, making it suitable for data archiving, e-book organization, log file numbering management, and other scenarios.
When organizing TXT text files, you often encounter this situation: a folder contains a batch of files with meaningless names, such as book1.txt, book2.txt, book3.txt, but each file internally contains numbers, titles, or names that can actually be used for archiving. If you open files one by one, copy content, and then go back to the folder to rename them, the steps are not only repetitive, but it's also easy to copy incorrectly, miss changes, or mess things up.
The problem this article aims to solve is: Batch renaming TXT files using partial text from file content. The following uses HeSoft Doc Batch Tool as an example to demonstrate how to extract the numbers following "Book ID" in the text content and set these numbers as the TXT file names in batch.
Applicable Scenarios
Batch renaming text files using file content is suitable for the following scenarios:
- E-books, articles, and data files have unique internal numbers, and you want to use the numbers as file names.
- Logs, orders, contract summaries, and other TXT files contain fields like IDs, serial numbers, and dates, which need to be archived by field.
- Downloaded or exported text file names are temporary names like book1.txt, book2.txt, and need batch standardization.
- The file content has a fixed format, such as Book ID:4829173056, and you only want to extract the numerical part as the file name.
HeSoft Doc Batch Tool is a batch file processing software designed for office scenarios, with its core value being the reduction of repetitive operations. For file organization tasks involving TXT, text data, etc., it allows users to process multiple files at once using rules, avoiding repeated opening, copying, pasting, and renaming.
Effect Preview: Before and After Processing
Before Processing: File names have no actual business meaning
Before processing, the names of the TXT files in the folder look like:
- book1.txt
- book2.txt
- book3.txt
- book4.txt
- book5.txt
These names only indicate a sequence and cannot directly reflect the number or content corresponding to the file. After opening one of the text files, you can see the first line of the file content contains information like Book ID:4829173056. The part actually needed for naming here is the number after the colon, 4829173056.


After Processing: Numbers extracted from file content as file names
After batch processing is complete, the file names will look like:
- 1958436720.txt
- 4829173056.txt
- 6094728315.txt
- 7305619482.txt
- 8640295173.txt
You can see that each TXT file no longer uses temporary names like book1, book2, but is named using the number extracted from the file content. The file extension remains .txt, making it easy to continue opening and managing them as text files.

Steps
Step 1: Enter the "Rename Text Files Using File Content" function
Open HeSoft Doc Batch Tool , and select File Name in the left function category. Find and click Rename Text Files Using File Content in the function list.

The purpose of this function is to batch read text file content and use certain text from the content as the file name. The function description in the screenshot is "Batch use certain text from text file content as the file name of that file," which perfectly matches the goal of this article—batch renaming files using TXT content.
After entering this function, the interface will guide you through a step-by-step wizard, including processes like "Select records to process," "Set processing options," "Set save location," and "Start processing." Complete them in order.
Step 2: Add the TXT files that need batch renaming
On the page for Step 1, "Select records to process," click the Add Files button at the top to add the TXT files that need processing to the list. If the files are centrally stored in the same folder, you can also use Import Files from Folder.

After adding the files, the list will display information such as serial number, name, path, extension, creation time, and modification time. For example, the screenshot shows that 5 text files from book1.txt to book5.txt have been imported, all with the txt extension.
The purpose of this step is to let the software clearly know which files are to be processed next. After adding, check if the files in the list are correct, and click Next at the bottom once confirmed.
Step 3: Set which part of the text to extract from the file content
After entering Step 2, "Set processing options," you need to tell the software which area of the TXT file content to extract text from and by what rule.

In the "Search Area," you can see options like First line of text and Text matched by custom formula. In this example, although the target content appears on the first line, we only need to extract the numbers after Book ID:, not the entire line. Therefore, select Text matched by custom formula.
Then enter the following in the "Regular Expression" input field:
(?<=Book ID:)\d+
The meaning of this expression is: Find the consecutive numbers immediately following Book ID:. For example, for the content Book ID:4829173056, the final matched result will be 4829173056.
If your file content format is different, you can adjust the matching rule based on the actual text. For instance, if the prefix is not Book ID, but Order ID, Number, ID, etc., you'll need to modify the fixed text in the regular expression accordingly.
Step 4: Set the position of the text in the file name
In the "Position" area on the same page, you can choose how the extracted text is applied to the file name. The screenshot provides the following options:
- Overwrite the entire file name
- To the left of the file name
- To the right of the file name
The goal of this article is to replace the original names like book1, book2 with the numbers from the file content, so select Overwrite the entire file name.
After selecting this option, the software will replace the original file name body with the matched number, and preserve the text file extension. For example, if 4829173056 is matched in book1.txt, it will become 4829173056.txt after processing.
If you only want to add content before or after the original file name, you can choose "To the left of the file name" or "To the right of the file name." However, for the requirement in this example—"using the content number as the new file name"—you should choose "Overwrite the entire file name."
Step 5: Continue setting the save location and start processing
After completing the extraction rule and naming position settings, click Next to enter "Set save location." Follow the interface wizard to complete the save location setting, then proceed to "Start processing."
Since this is a batch rename operation, it's recommended to confirm these three points before formally processing:
- Are the TXT files in the file list all the files to be processed this time?
- Can the regular expression accurately match the target content?
- Is the naming method selected as "Overwrite the entire file name"?
Execute processing after confirming there are no errors. Once processing is complete, go back to the folder to see that the TXT files have been batch renamed to the numbers in their content.
Regular Expression Explanation: Why Use (?<=Book ID:)\d+
In this example, the first line of the text file is similar to:
Book ID:4829173056
We only want the number part, and don't want to include "Book ID:" in the file name, so we used:
(?<=Book ID:)\d+
- (?<=Book ID:): Indicates that the position of the match must be preceded by "Book ID:", but does not include "Book ID:" itself in the result.
- \d+: Indicates matching one or more digits.
Therefore, the file name text ultimately extracted by the software is the numerical ID. This method is suitable for TXT files with relatively fixed content formats, especially when each file contains the same field name but different field values.
Common Questions and Notes
1. What happens if a file doesn't have "Book ID"?
If a TXT file doesn't contain content matching the rule, the software cannot extract a new file name based on that rule. Before processing, it's recommended to spot-check a few files to confirm they all have a structure similar to Book ID:digits.
2. Does the regular expression need to be copied exactly?
Not necessarily. The example in this article is suitable for the Book ID:4829173056 format. If your content is "Number:4829173056" or "ID=4829173056", you'll need to modify the expression based on the actual prefix.
3. Can the extracted text include Chinese characters or titles?
The idea of this function is to extract specified text from text file content as the file name. As long as the target text can be located through a search area or matching rule, it can be used for renaming. During actual use, be careful not to include special characters that the system does not allow in file names.
4. Will this change the content of the TXT files?
What this article demonstrates is file name processing; the goal is to batch modify file names. Before and after processing, the focus is on the file name changing from book1.txt to a number.txt; the file extension remains txt.
5. Do I need to back up before batch processing?
For important data, it's recommended to copy a test folder first before performing batch renaming. Once the rules are confirmed correct, then process the actual files. This helps avoid generating unexpected file names due to inaccurate rule settings.
Summary
Batch renaming TXT files using partial text from file content is essentially about offloading the repetitive sequence of "opening files, finding numbers, copying numbers, returning to the folder, modifying file names" to office software for automatic completion. Using the "Rename text files using file content" function in HeSoft Doc Batch Tool , you just need to add files, set matching rules, choose to overwrite the file name, and execute processing to standardize the naming of multiple text files all at once.
If you are organizing a large number of TXT, log, data, or e-book text files, and the file content already contains numbers, titles, or other identifiable fields, it is recommended to use this batch renaming method. It can significantly reduce repetitive work, improve file archiving efficiency, and make subsequent searching and management clearer.