When a folder contains a large number of txt text files, but the filenames are only temporary names like book1, book2, subsequent retrieval, archiving and delivery will be very troublesome. This article takes HeSoft Doc Batch Tool as an example to demonstrate how to use wildcard regular expressions to extract Book IDs from text content and batch use these contents as new filenames. It is suitable for batch organization scenarios such as e-book materials, log texts, exported reports, numbered documents, etc.
During daily office work and data organization, you often encounter this issue: folders contain numerous text files with temporary numerical filenames, such as book1.txt, book2.txt, book3.txt, but the truly valuable identifiers, titles, or business information are written within the file contents. Opening each txt file individually, copying the identifier, and returning to the folder to manually rename is not only time-consuming but also prone to copying errors, missed files, or overwriting files with the same name.
This article addresses this type of repetitive task: using the "Rename text files using file content" feature in the office software " HeSoft Doc Batch Tool ", combined with wildcard regular expressions, you can match the required content from each txt file and batch-use the match results as the new filenames. In the example, we extract the Book ID number from the first line of text, changing the original filenames like book1.txt, book2.txt, etc., in batch to identifier-based filenames like 4829173056.txt, 6094728315.txt.
Applicable Scenarios: Which Text Files Are Suitable for Batch Renaming by Content
"Rename text files using file content" is suitable for processing txt files with relatively fixed structures and clear identifiers within the content. As long as each file contains text that can be matched by a rule, it can be extracted as a filename using a regular expression. Common scenarios include:
- Organizing ebooks, articles, manuscripts: The filenames are temporary names, but the body contains information like Book ID, article number, title, author name, etc.
- Archiving system logs or exported records: Each txt file contains order numbers, user IDs, device numbers, serial numbers, and this information is needed to name the files.
- Batch report renaming: Reports contain project numbers, customer numbers, dates, etc., and need to be unified into standardized filenames.
- Organizing data collection results: The filenames of scraped or exported text files are meaningless, but the content has unique identifiers useful for subsequent filtering, searching, and archiving.
Compared to manually opening files, copying content, and renaming, the advantage of a batch processing tool is clear: import multiple files at once, set matching rules uniformly, and the software automatically reads each file's content and generates a new filename. For tens, hundreds, or even more txt files, the efficiency gain is very significant.
Effect Preview: Changes Before and After Processing
Before processing, the text filenames in the folder are just book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. Such names only indicate sequence and cannot directly reveal the actual identifier or content information corresponding to the file.

Opening one of the text files reveals that the first line of content contains information like Book ID:4829173056. This means what we actually want as the filename is not the fixed text "Book ID:", but the numeric identifier after it.

After processing is complete, the originally meaningless filenames like book1.txt, book2.txt are batch replaced with the numeric identifiers extracted from the text content, such as 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt. This gives the filenames immediate identification value, making subsequent searching, sorting, and archiving much more convenient.

Operation Steps: Using Regular Expressions to Batch-Use Text Content as Filenames
Step One: Enter the "Rename text files using file content" feature
After opening HeSoft Doc Batch Tool , select "File Name" in the left-side feature categories. The page will display multiple feature cards related to filename processing, such as find and replace filename keywords, insert text, add prefix/suffix, case conversion, etc. The one you need to select here is "Rename text files using file content".

The purpose of this step is to enter the workflow specifically designed for reading and renaming based on the content of txt files. This feature does not simply replace characters in the filename; it reads the internal text of the file and extracts content as the new name according to specified rules. Therefore, if your requirement is to "name a file using the ID, title, or identifier inside it," you should select this feature.
Step Two: Add the txt files to be processed
After entering the feature page, you can see action buttons like "Add Files," "Import files from folder," "Clear," and "More" at the top of the interface. In the example, 5 txt files have been imported, and the list shows information such as sequence number, name, path, extension, creation time, and modification time.

If you only need to process a few specific files, you can use "Add Files"; if an entire folder contains text files for processing, "Import files from folder" is more suitable. After importing, it is recommended to first check that the extensions in the list are txt and confirm that the paths are correct, to avoid processing unrelated files together.
The expected result after completing this step is: all text files needing batch renaming appear in the pending list, and the record count matches the actual number of files to process. The example shows a record count of 5 at the bottom of the list, indicating that 5 txt files will be batch processed this time.
Step Three: Set the search area and regular expression
Click "Next" to enter "Set processing options." In the search area, you can see options like "First line of text" and "Text matched by custom formula." The example selects "Text matched by custom formula" and enters the following in the "Regular Expression" input box:
(?<=Book ID:)\d+
The meaning of this regular expression can be broken down as follows:
- Book ID: is the fixed prefix, indicating where to start matching from text containing this string.
- (?<=Book ID:) indicates matching the content that follows "Book ID:" without including "Book ID:" itself in the result.
- \d+ indicates matching one or more digits.
Therefore, when the text contains Book ID:4829173056, the final result extracted by the software is 4829173056, not the complete "Book ID:4829173056". This perfectly meets our need to use only the numeric identifier as the filename.
If your text content format differs, you can adjust the regular expression accordingly. For example, if the file contains "Number:A20260506", you would need to write a matching rule for the content following "Number:". The key principle is: the expression must be able to consistently match the specific text segment you want as the filename within each file.
Step Four: Set the positioning rule for the new filename
In the same page below, you can see the "Position" setting, where the example selects "Overwrite entire filename". This means the software will completely replace the original filename body with the matched text, while the .txt extension will be preserved. Therefore, book1.txt, after matching 4829173056, will become 4829173056.txt.
Besides overwriting the entire filename, the interface also shows position options like "On the left of the filename" and "On the right of the filename". For the scenario described in this article where "the original filename has no value to keep, and you only want to use the content identifier as the new name," selecting "Overwrite entire filename" is the most direct approach. If you wish to preserve the original filename while appending content to its left or right, you can choose the corresponding position based on your actual archiving rules.
Step Five: Proceed to next step, set save location, and start processing
After completing the regular expression and position settings, click the "Next" button at the bottom of the page. Following the interface workflow, you will then enter the "Set save location" and "Start Processing" stages. It is recommended to confirm the save location before formal processing, especially when batch renaming important files. You might prefer to choose a backup directory or confirm the original files are backed up first, to avoid affecting the source materials if the rule settings are incorrect.
Once you have confirmed that the file list, matching rules, and save location are all correct, execute the start processing command. After processing is complete, return to the folder view, and you will see the text files have been batch renamed according to the Book ID in their content.
Key Points for Setting Wildcard Regular Expressions
Many users find "regular expressions" intimidating, but in the context of batch file renaming, it usually isn't difficult if you grasp the idea of "fixed prefix + content to extract". The key in this article's example is that every text file has a uniform format: the first line contains "Book ID:" followed by a string of digits. Therefore, we only need the software to recognize the digits that come after "Book ID:".
If your content is a title, English name, or mixed identifier, you must adjust the rule based on the character type. Digits can use \d+, consecutive English letters or digits can use corresponding character range rules; if only processing the first line, you can also combine this with the "First line of text" option in the interface for simplification. For actual operation, it's recommended to first test the rule with a small number of files, confirm the new filenames meet expectations, and then import the complete folder for batch processing.
Common Questions and Precautions
1. Why didn't some files get renamed after processing?
This is usually because the regular expression did not find a match in that file's content. For instance, some files might say "BookID:" without the space, or there might be a space after the colon, either of which could cause a match failure. It's advisable to open the unrenamed file, check the content format against the expression.
2. Can the filename contain symbols like colons or slashes?
Windows filenames have restrictions on certain symbols; for example, colons, slashes, and backslashes cannot be part of a filename. This article uses a regex to extract only the numeric identifier specifically to avoid bringing the colon from "Book ID:" into the filename, reducing the risk of naming failure.
3. Do I need to keep the original book1, book2 names?
If the original filename still has reference value, it's not recommended to choose overwrite the entire filename. You might consider adding the matched content to the left or right of the filename. But if the original name is just a temporary sequence number, choosing overwrite the entire filename is clearer.
4. Is a backup necessary before batch processing?
A backup is recommended. Batch renaming is inherently an efficiency-boosting operation, but a wrongly written rule could result in unexpected filenames. Especially when handling large numbers of business files, customer materials, or project documents, backing up first before batch processing is the safer approach.
Summary: Let File Content Automatically Become the Filename, Reducing Repetitive Work
With HeSoft Doc Batch Tool , you can transform the task of needing to open, copy, paste, and rename files one by one into a process of importing once, setting rules once, and completing the work automatically in batch. The example in this article uses (?<=Book ID:)\d+ to extract the Book ID numbers from txt text and overwrite them as the new filenames, suitable for the standardized organization of large numbers of text files.
If you are handling ebooks, logs, reports, exported data, or other txt text materials, and the file contents include recognizable identifiers or titles, you can follow the steps in this article: test with a small number of files first, then import the complete folder for batch processing. This not only saves a significant amount of repetitive labor but also significantly improves the efficiency of subsequent searching, archiving, and collaboration.