When a large number of TXT text files have temporary names like book1 or book2, but the meaningful numbers, order numbers, Book IDs, or archive numbers are actually located within the file content, manually opening, copying, and renaming them is extremely inefficient. This article uses HeSoft Doc Batch Tool as an example to demonstrate how to use the "Rename Text Files Using File Content" feature. By applying regular expressions, you can extract specific numbers from the text content and batch replace them as new file names. This is ideal for batch organization scenarios involving books, materials, logs, contract numbers, data records, and more.
When organizing text data, a common issue arises: folders often contain numerous txt text files with temporary names like book1.txt, book2.txt, book3.txt, while the actual IDs used for archiving, retrieval, and differentiation are written inside the file content. For example, the first line of each text file might be "Book ID:4829173056". Opening each file individually, copying the ID, closing the file, and returning to the folder to rename it is not only time-consuming but also prone to omissions and errors.
This article addresses the problem of "how to batch rename multiple text files using their content via wildcards/regex". We will use screenshots with the office software HeSoft Doc Batch Tool as an example to demonstrate how to extract the Book ID numbers from the body of txt files and batch-apply them as the new file names. Once completed, files like book1.txt, book2.txt will become names like 1958436720.txt, 4829173056.txt, making future searches and archiving much more convenient.
Applicable Scenarios: Which Files Are Suitable for Batch Renaming Based on Content
This method is particularly suitable for situations where "the file names are valueless, but the file contents contain fixed fields." As long as each text file includes similarly formatted fields, you can use a regular expression to extract the target content and set it as the new file name in a batch.
Common scenarios include: book data files containing Book IDs, ISBNs, or chapter numbers; customer profile texts containing customer IDs, phone numbers, or order numbers; log files containing device numbers, dates, or serial numbers; contract or memo txt files containing contract numbers or project numbers; and exported txt, csv, or log files containing unique identifiers. Although the screenshots in this article demonstrate the process with .txt text files, the concept applies equally well to the organization of many types of structured text content.
Compared to manual renaming, the core value of batch file processing lies in reducing repetitive labor. Especially as the number of files grows from dozens to hundreds or thousands, the efficiency difference from using office software to automatically extract content and rename becomes significantly apparent.
Result Preview: File Name Changes Before and After Processing
Before: File names are temporary numbers, making it impossible to directly determine the content
Before processing, the file names in the folder are book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. Such names only indicate a sequence, cannot reflect the actual internal IDs of the files, and are not conducive to later searching by ID.

Opening one of the text files reveals that the first line contains the information we actually need as the file name: Book ID:4829173056. In other words, we don't want to use a temporary name like book2; we want to extract 4829173056 and use it as the new file name.

After: The ID from the body becomes the new txt file name
After batch processing is complete, the file names have been changed to the numeric IDs extracted from the text content, such as 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt. The extension remains .txt, and the file content itself does not need to be manually copied and pasted.

This outcome shows that the software, following our set regular expression, located the target field in each text file and used the matched content to rename the file.
Procedure: Batch Renaming txt Files by Content Using Regular Expressions
Step 1: Enter the "Rename Text Files Using File Content" Function
After opening HeSoft Doc Batch Tool , you can see multiple tool categories on the left, including File Name, Folder Name, File Organization, Word Tools, Excel Tools, PDF Tools, Text Tools, etc. Since we are dealing with file names, and the new names come from the text file content, enter the File Name category.
In the list of file name functions, select "Rename Text Files Using File Content". The description on the function card in the screenshot reads "Batch use text from text...", meaning the specified part of the text content will be extracted for file naming.

The purpose of this step is to confirm that we are using a specialized batch function for "extracting values from text content to rename files," rather than a simple find-and-replace file name function.
Step 2: Add the txt Files to be Processed
After entering the function page, the top interface shows that the current function is Rename Text Files Using File Content. The first step is "Select records to process". You can click Add Files to add multiple txt files to the task list; if the files are concentrated in one folder, you can also click Import Files from Folder.

After importing the files, the table lists information such as sequence number, name, path, extension, creation time, and modification time. As shown in the screenshot, book1.txt through book5.txt have been successfully added to the list, all with the .txt extension and located in the D:\test directory. After confirming the number and paths of the files are correct, click Next at the bottom to enter the processing option settings.
It's recommended to focus on two checks at this step: first, ensure all text files needing processing have been added; second, confirm that no unneeded files were mistakenly added. Since subsequent renaming will be performed in batch, confirming the list beforehand can help avoid unnecessary rework.
Step 3: Select the Search Area and Fill in the Regular Expression
After entering "Set Processing Options", the interface provides settings for the search area and regular expression. In the screenshot, Text matched by a custom formula is selected, and the following is entered in the "Regular Expression" input box:
(?<=Book ID:)\d+

This regular expression's function is to find the consecutive digits located after "Book ID:" in the text content. The part (?<=Book ID:) is a positive lookbehind assertion, meaning it matches content immediately preceded by "Book ID:" but does not include "Book ID:" itself in the result; \d+ matches one or more digits. Therefore, if the first line of the text is "Book ID:4829173056", the final extraction will be 4829173056, not the full "Book ID:4829173056".
In the "Position" area, the screenshot shows Overwrite the entire file name is selected. This means the new file name will entirely use the extracted ID, rather than appending the ID to the left or right of the original file name. For example, book2.txt will be renamed to 4829173056.txt, not 4829173056book2.txt or book24829173056.txt.
If your text format is not "Book ID", but something like OrderNo:123456, ID=ABC001, or ISBN:978xxxx, you'll need to adjust the regular expression based on the actual content. The core principle is to find the static prefix and then match the target characters following it.
Step 4: Set the Save Location and Start Batch Processing
After completing the regular expression and file name overwrite method settings, continue by clicking Next. The interface flow shows subsequent stages for "Set Save Location" and "Start Processing". It is generally recommended to confirm the save method before formal execution, especially for batch renaming tasks; it's best to test the rules on a small number of files first to ensure correctness.
Once confirmed, proceed to the start processing stage. The software will read the content of each txt file in the list, search for matching text according to the regular expression, and write the matched result into the file name. After processing is complete, return to the folder to see that the file names have changed from book1.txt, book2.txt, etc., to their corresponding numeric IDs.
Regular Expression Explanation: Why This Rule Precisely Extracts the Book ID
The rule used in this example is (?<=Book ID:)\d+. Many users find regular expressions complex, but this example actually only uses two key points.
First, "Book ID:" is a fixed marker. A similar format exists in each text file, making it a reliable anchor. Second, \d+ is used to match digits. As long as digits follow the Book ID, they can be accurately extracted.
The advantage of this syntax is that the characters "Book ID:" are not brought into the file name, leaving only the truly needed ID. For batch renaming, this is important because the more standardized the file name, the easier it is for sorting, searching, and importing into systems later.
Common Questions and Considerations
1. Every text file must contain a matchable field
If a txt file lacks "Book ID:" or has non-digit characters following it, the regular expression might not match anything. It is recommended to spot-check several files before batch processing to confirm the field format is consistent.
2. New file names cannot contain characters prohibited by the system
Windows file names typically cannot contain characters like \ / : * ? " < > |. This example extracts pure numbers, so it's relatively safe. If you are extracting titles, names, or descriptive text, you need to check for illegal characters.
3. Be aware of duplicate file name conflicts
If multiple text files contain the same Book ID, a name conflict may arise during batch renaming. Before processing, first check if the IDs are unique, especially for fields like order numbers, customer IDs, or file codes.
4. Test in small batches before processing a large number of files
If the regular expression is written incorrectly, it might extract nothing or extract incorrect text. It is recommended to first test on 3 to 5 files, and only after confirming the results meet expectations should you execute the batch on the complete folder.
Summary: Use Office Software to Batch Extract Content for Renaming, Reducing Repetitive Work
Using the "Rename Text Files Using File Content" function in HeSoft Doc Batch Tool , we can batch extract specified fields from the body of txt files and automatically apply them to the file names. For tasks involving organizing large volumes of text files, data archiving, book ID management, log file classification, and similar work, this method is more efficient and stable than manually opening files, copying IDs, and renaming them.
If your files also suffer from "non-standard file names, but the body contains IDs, order numbers, or key fields", you can follow the steps in this article. Prepare a set of sample files, first write a regular expression for testing, and then batch process all files. This ensures naming accuracy while significantly reducing repetitive operation time.