This article explains how to use HeSoft Doc Batch Tool to extract the Book ID from the body of multiple TXT text files and batch rename them to the corresponding file names. In the example, the original file names are book1.txt, book2.txt, etc., and the first line of the file content contains a number like Book ID:4829173056. By selecting the "Rename text files using file content" feature, after importing the files, use the regular expression (
When organizing a large volume of TXT text files, a common problem often arises: the file names themselves lack business meaning. For example, names like book1.txt, book2.txt, book3.txt only indicate a sequence but do not reveal which book, record, or number is inside the file. If the body of each text file contains a unique identifier — such as a Book ID, order number, contract number, or article number — it is ideal to extract this content and use it as the file name.
The typical manual approach involves: opening the first TXT, finding the ID, copying it, closing the file, returning to the folder, renaming the file, and then processing the next one. This is acceptable when there are only a few files, but with dozens or hundreds of TXT documents, this repetitive labor is not only time-consuming but also prone to copying errors, omissions, or duplicate names. This article addresses this problem: using the batch file processing capability of the office software " HeSoft Doc Batch Tool ", you can extract specified characters from text file content using wildcard regular expressions and batch rename these TXT files.
Applicable Scenarios: Which Files Are Suitable for Batch Renaming by Content
This article demonstrates batch renaming of TXT text files, but the concept applies to many scenarios where text content serves as the naming basis. As long as stable, identifiable, and extractable fields exist within the file content, you can consider using regular expressions to match them and use the results as the new file names.
For instance, the first line of a book file contains a Book ID; a log file contains a Trace ID or device number; exported business records contain an order number, customer number, or batch number; crawled or archived text content contains an article ID, page ID, or title number. For these files, continuing to use temporary names like book1.txt, data2.txt, record_003.txt makes subsequent searching, archiving, and comparison cumbersome. After changing the file name to the unique identifier from the body text, the folder list itself directly reflects the file content.
HeSoft Doc Batch Tool is a batch document processing software designed for office scenarios, with its key value being the ability to turn file operations that originally required manual one-by-one processing into a single batch execution. This article uses the "Rename Text Files Using File Content" feature, suitable for extracting content from txt text files and batch renaming. If your files are Word documents, such as doc or docx, you can also see a similar function entry for "Rename Word Files Using File Content" in the interface; similarly, for PDFs, there is a corresponding entry for PDF file content renaming. This article focuses on TXT text files.
Effect Preview: How File Names Changed After Processing
Before Processing: File names were temporary numbers like book1, book2
The folder before processing contained 5 TXT files, named book1.txt, book2.txt, book3.txt, book4.txt, and book5.txt. The specific Book ID corresponding to these texts could not be discerned from the file names, nor could one quickly determine the file content.

Opening one of the text files reveals that the first line of the body contains content similar to Book ID:4829173056. The red arrow in the screenshot points to the number part to be extracted as the file name. What is actually needed as the file name here is the number after the colon, 4829173056, not the entire line of text.

After Processing: File names become the Book ID from the body text
After the batch processing is complete, the original files like book1.txt, book2.txt are renamed to 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, and 8640295173.txt. This means the software automatically read the specified content in each TXT file and used the matched numbers as the new file names.

The value of this result is direct: the folder list is no longer a set of meaningless temporary names but business numbers corresponding to the body content. Later, when searching for a specific Book ID, you only need to search the file name in the folder, without opening each text file individually.
Operation Steps: Batch Renaming TXT Files Using Wildcard Regular Expressions
Step 1: Enter the "Rename Text Files Using File Content" Function
After opening HeSoft Doc Batch Tool , select the "File Name" category on the left. The main interface will list multiple functions related to batch file name processing, such as find and replace in file names, insert text, add prefix/suffix, delete text from file names, etc. The function we will use in this article is the 8th item: Rename Text Files Using File Content.

The purpose of selecting this function is to let the software read the internal content of TXT files, extract text according to specified rules, and use the extraction result for file naming. Unlike ordinary batch renaming, it changes the name based on the file body, not the original file name, making it particularly suitable for processing files with chaotic names but containing fixed identifiers in their content.
Step 2: Add the TXT Files to be Processed
After entering the function page, the interface moves to Step 1, "Select records to be processed". Here you can see buttons like "Add Files" and "Import Files from Folder" at the top. In the example, 5 TXT files have been imported, and the list displays information such as sequence number, name, path, extension, creation time, and modification time.

The purpose of this step is to add the text files that need batch renaming to the processing list. You can add files individually or import them in batch from a folder. After importing, it is recommended to check the list: confirm the file extension is txt, confirm the path is the target folder, and confirm that the record count matches expectations. The bottom of the example shows a record count of 5, indicating that 5 text files will be batch processed this time.
If files not intended for processing are imported, you can remove them using the delete operation on the right side of the list; if you need to reselect, you can also use the clear function on the interface before importing again. This helps avoid renaming unrelated files along with the target ones.
Step 3: Set the Search Area to "Text matched by custom formula"
Click "Next" to enter Step 2, "Set processing options". In the "Search Area", the interface provides options like "First line of text" and "Text matched by custom formula". In the screenshot, Text matched by custom formula is selected because we do not simply want the entire first line as the file name, but only the number following the Book ID.

This step is crucial. If "First line of text" were chosen, the file name might become the complete content like "Book ID:4829173056"; by choosing the custom formula match, you can precisely extract the needed part using regular expressions. In the example, the Book ID format is fixed as Book ID:number, so we can match only the number after the colon.
Step 4: Enter the Regular Expression (?<=Book ID:)\d+
Fill in the "Regular Expression" input box with:
(?<=Book ID:)\d+
This wildcard regular expression can be understood as: find consecutive numbers located after Book ID:. Here, (?<=Book ID:) indicates that the matching position must be preceded by "Book ID:", but "Book ID:" itself is not included in the result; \d+ indicates matching one or more digits. The final match result is a pure numeric ID like 4829173056.
Therefore, if the file content contains Book ID:4829173056, the main part of the file name extracted by the software will be 4829173056. Since the original file extension is txt, the resulting file after processing will be 4829173056.txt. This is exactly the post-processing effect seen in the screenshots.
Step 5: Set the Naming Position to "Overwrite the entire file name"
In the "Position" area, the screenshot shows that Overwrite the entire file name is selected. This means the software will replace the original file name body with the regex-matched text, rather than appending it to the left or right.
If the original file name is book2.txt and the matched content is 4829173056, then selecting "Overwrite the entire file name" will result in 4829173056.txt. This setting is suitable for scenarios where you want to completely discard the original temporary file name. The interface also shows other position options like "On the left side of the file name" and "On the right side of the file name". If your requirement is to retain the original file name and add the ID, you can choose according to the actual situation; however, the goal of this example is to directly use the Book ID as the file name, so overwriting the entire file name is more appropriate.
Step 6: Proceed to the Next Step, Set the Save Location, and Start Processing
After completing the regular expression and position settings, click "Next" at the bottom. In the interface flow, you can also see Step 3 "Set save location" and Step 4 "Start processing". This shows that the software follows a wizard-style flow, allowing the user to confirm the file save location before executing the batch renaming.
In actual office processing, it is recommended to confirm two points before starting: first, whether the save location aligns with your archiving habits; second, whether you have backed up the original files or confirmed that the current processing result can overwrite the original names. Once confirmed, proceed to start processing. After completion, return to the folder to see that the file names have been batch updated according to the Book IDs in the body text.
Regular Expression Explanation: Why This Rule Precisely Extracts the Book ID
Many users find the term "regular expression" complex, but this example actually uses only one very practical rule: extracting numbers from after a fixed text prefix. The focus of the expression (?<=Book ID:)\d+ is to separate "positioning" and "extraction".
"Book ID:" is the positioning basis, telling the software where to start looking; \d+ is the content truly desired as the file name, representing a continuous string of digits. The benefit of this is that the file name will not contain the characters "Book ID:" nor any body title or paragraph text, retaining only the ID itself.
If your text format is not "Book ID" but something like "Number: 123456", "ID=123456", or "Order No: 123456", the logic is similar: first find the stable text preceding the ID, then let the regular expression extract the following digits. It is important to note that the expression shown in this article's screenshots is designed for the Book ID:number format. If your file content format differs, the expression will need corresponding adjustments.
Common Questions and Considerations
1. Must every TXT file contain the matching content?
Yes, it is recommended. Batch renaming relies on the match results within the file content. If a TXT file has no Book ID, or if the characters following "Book ID" are not digits, the expected new file name may not be obtained. It is best to spot-check several files before processing to confirm consistent formatting.
2. Can the extracted content contain Chinese characters or special symbols?
From a file naming perspective, it is recommended to extract safe characters like numbers, letters, hyphens, and underscores as much as possible. Windows file names are not suitable for containing certain special symbols. The example extracts a purely numeric Book ID, making it highly suitable for use as a file name.
3. What if the same ID is extracted from multiple files?
If the Book ID in the content of multiple files is exactly the same, name conflicts may occur during batch renaming. Before formal processing, you should try to ensure the Book ID is a unique field. If number duplication is possible, consider appending the original file name, date, or other information to the left or right of the file name. However, the example in this article directly overwrites the entire file name.
4. Why not directly use the first line of text as the file name?
Because the first line usually contains both a field name and the identifier, such as "Book ID:4829173056". Using the first line directly might include "Book ID:" in the file name, and in other files, the first line might even contain more descriptive text. Using a regular expression allows you to extract only the truly needed numeric part, resulting in cleaner and more uniform file names.
5. Is a backup necessary before processing?
Batch file processing is a high-efficiency operation, meaning it can affect multiple files at once. When using a new regex rule for the first time, it is recommended to test it on a small number of files first, confirm the results are correct, and then process all files. For important documents, a backup beforehand is advised to prevent file names from not meeting expectations due to incorrect rule settings.
Summary: Turning Repetitive Renaming into a One-Time Batch Process
With the "Rename Text Files Using File Content" function in HeSoft Doc Batch Tool , you can consolidate the manual workflow of opening TXTs, finding Book IDs, copying numbers, and renaming files one by one into just a few steps: importing files, setting the regular expression, confirming the position, and starting the process. For office scenarios involving archiving large volumes of text files, organizing document numbers, and standardizing batch naming, this method significantly reduces repetitive labor and lowers the risk of manual copying errors.
If your TXT files also contain stable numbers, IDs, order numbers, or other identifiable fields, you can first spot-check the file format, then refer to this article and use a regular expression like (?<=Book ID:)\d+ for matching. Once you confirm the rule is correct, you can use batch processing software to complete the file renaming in one go, making your folder structure clearer and subsequent searching and management more efficient.