When the names of a batch of TXT files are only temporary numbers like book1 and book2, but the file content contains key fields such as Book ID, order number, or file number, manually copying and renaming them one by one is very inefficient. This article introduces how to use the "Rename Text Files Using File Content" function in HeSoft Doc Batch Tool to import multiple TXT files, match the numbers in the body using regular expressions, and batch overwrite the original file names, making the archiving, retrieval, and subsequent processing of text data more standardized.
Many office documents don’t come with standardized filenames right from the start. For example, articles downloaded in batches, collected TXT files, or text records exported by systems often have names like book1.txt, book2.txt, or random serial numbers. The fields that can truly identify the file content are often written inside the file body, such as the first line: Book ID:4829173056. This brings a typical pain point: key information isn't visible in the folder, so you must open files to search; if you want to turn a number in the body into the filename, you have to copy, paste, and rename one by one, which is very time-consuming.
This article will demonstrate a more efficient batch approach: using the HeSoft Doc Batch Tool in the screenshot, and through the "Use File Content to Rename Text Files" feature, extract content from the TXT body that matches wildcard/regex rules and batch-use it as filenames. In the example, we will extract the numeric ID following "Book ID:" from each text file, and batch-generate new filenames like 4829173056.txt. This reduces repetitive work and improves file archiving and retrieval efficiency.
Applicable Scenario: Typical needs for extracting fields from text bodies as filenames
"Rename based on file content" is suitable for files with meaningless names but bodies containing fixed fields. Compared to regular filename substitution, it doesn’t just look for keywords within the original filename; it reads the internal file content and uses the matched text for naming.
1. Batch organizing ebooks, articles, or reference texts. If a TXT body contains fields like Book ID, title, author, chapter number, you can use these as the filename or filename prefix. This article's example extracts the Book ID number.
2. Organizing system-exported business texts. For instance, each text file might contain an order number, customer ID, contract number, work order number, or device number. Writing these numbers into the filename makes subsequent searching by number much more direct.
3. Cleaning up files generated by automated programs. Files generated by crawlers, scripts, or batch tasks often just have sequential numbers, but the body usually contains a unique ID. Using batch processing software, you can uniformly rename them after generation, avoiding manual secondary organization.
4. Establishing unified archiving rules. When filenames are standardized to a unique ID from the body, folder sorting, cross-system matching, backups, and handovers become clearer. For large numbers of TXT files, this standardized naming significantly reduces communication costs.
Please note that this example is based on the TXT file structure in the screenshot: the first line of the body contains "Book ID:" followed by a number. If your text field names, spaces, or line breaks differ, you should adjust the matching expression based on your actual content.
Effect Preview: Before processing, filenames have no business meaning
Before processing, the multiple text files in the folder are named book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. From these filenames, it is impossible to determine the actual ID corresponding to each text, making it inconvenient to associate with other tables or system data.

Opening one of the TXT files, you can see the first line of the body contains Book ID:4829173056. The red arrow highlights where the ID is located. For text with this stable structure, we don't need the entire line as the filename, just the number after the colon.

If handled manually, you would need to open each file, copy the ID, and return to the folder to rename. This might be acceptable for 5 files, but for 500 TXT files, the repetitive work consumes significant time and is prone to misalignment in copying, missed changes, and inconsistent naming.
Effect Preview: After processing, filenames become the Book ID from the body
After processing, the filenames in the folder have turned into the numbers extracted from the file body, such as 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt. These names serve as indexes much better than the original book1, book2, etc.

From the results, it's clear the software doesn't just generate new names in sequence, but reads the content of each TXT file individually and extracts its respective Book ID as the filename. This is the key difference between the "Use File Content to Rename Text Files" feature and standard batch renaming tools.
Steps: Batch Renaming TXT Files Using Regex
Step 1: Open the corresponding feature in the file name tool
After starting HeSoft Doc Batch Tool , the left function pane contains multiple categories. Since the goal is to modify filenames, first click "File Name" on the left. In the right feature card, select the 8th item, "Use File Content to Rename Text Files". In the screenshot, this feature is highlighted, indicating it is specifically for "batch using certain text from text file content as the filename for that file."

The expected result of this step is entering a step-by-step processing interface. The top of the interface will display the current feature name, and the subsequent workflow includes selecting files, setting processing options, setting the save location, and starting processing. For users unfamiliar with batch renaming, the step-by-step approach reduces the risk of missing settings.
Step 2: Add or import the TXT files from a folder
After entering the feature, you need to select the records to process first. You can see two main entry points in the upper right of the interface: "Add Files" and "Import Files from Folder". The former is good for selecting a few specific files, while the latter is suitable for importing a batch of TXT files from a folder at once.

In the screenshot, 5 records have been imported, and the list shows file name, path, extension, creation time, and modification time. It's recommended to carefully check: are all the files TXT files that need processing; are the paths correct; does the record count match the target file count in the folder? If files are added by mistake, you can remove them using the delete icon in the operation column on the right; if you need to reselect, use the "Clear" button on the interface to clear the list.
After confirming everything is correct, click "Next" at the bottom. The purpose of this step is to add all target text files to the same batch task, so you only need to set the rule once, and the software will apply it to these files.
Step 3: Select "Text matched by custom formula" as the search area
On the "Set Processing Options" page, first set the "Search Area." In the interface, you'll see two options: "First line text" and "Text matched by custom formula". This example selects the latter, because we want to further extract the number from the first line, rather than directly using the entire line "Book ID:4829173056" as the filename.

The advantage of selecting "Text matched by custom formula" is that you can control the final naming content with more precise rules. For instance, if the body has fixed tags, prefixes, or formats, regex can extract exactly the part you need. For batch files, this is more stable than manual cutting.
Step 4: Enter the regex to match the Book ID number
Enter the following in the "Regex" input box: (?<=Book ID:)\d+. Its purpose is to match all consecutive digits immediately following "Book ID:". In the example "Book ID:4829173056", the match result is 4829173056.
There are two key points here. First, "Book ID:" is the fixed text used for positioning, helping the software locate where the number occurs. Second, \d+ represents consecutive digits, ensuring the extracted content is the ID, not subsequent titles or body paragraphs. As long as the field format is consistent across multiple TXT files, the software can batch-apply the same rule to all files.
If you want to extract not a Book ID, but an order number, archive ID, or other field, you can rewrite the expression using the same logic. For example, if there's a fixed prefix, use it as the positioning basis and then match the subsequent digits or text. The actual rule should be based on your file content.
Step 5: Set the naming position to overwrite the entire filename
In the "Position" area, this example selects "Overwrite entire filename". This means the extracted ID will directly become the new main filename body, replacing the original book1, book2, etc. The screenshot also shows options "On the left side of the filename" and "On the right side of the filename," which are more suitable for adding prefixes or suffixes, but the goal here is to completely name using the body ID, so overwriting is chosen.
After completing the settings, click "Next" at the bottom to continue. Following the interface flow, you will proceed to "Set Save Location" and "Start Processing." Before officially starting, it's recommended to double-check if the regex is correct, the file list is accurate, and the save location meets expectations. After processing, you will get the ID-named filenames shown in the preview above.
FAQ and Notes
Must the spaces in the regex exactly match the body?
Yes. The example expression matches the case where a number immediately follows "Book ID:". If your actual text is "Book ID: 4829173056" (with a space after the colon), you need to adjust the rule according to the actual format. It's advisable to open a few sample texts before batch processing to confirm the field format is consistent.
Can I use the first line text directly as the filename?
The interface does have the "First line text" option. If you want the filename to become the entire line of text, you can choose it. But in this example, the first line includes "Book ID:" and the colon, and we only need the numeric ID, so choosing "Text matched by custom formula" is more suitable.
Which characters cannot appear in filenames?
Windows filenames usually don't accommodate special characters like colons, slashes, question marks, or asterisks. One advantage of using regex to extract only digits is that it avoids these illegal or irregular characters. If you are extracting title text, pay attention to whether the title contains symbols unsuitable for filenames.
Why is the file sorting different after processing?
After filenames become numeric IDs, the file explorer will sort by the new names or modification time, so the display order may differ from the original book1 to book5 order. This is normal and does not mean the content mapping is wrong. You can spot-check by opening files to confirm the ID comes from the corresponding body.
How to reduce the risk of batch renaming?
It's recommended to test with a small number of files first, such as importing 3 to 5 samples, and confirm the output is correct before processing the entire batch. For important data, backing up the original folder first is advisable. The advantage of batch processing software is speed, but it also demands precise rule settings.
Summary: Batch rename using body IDs for easier TXT data management
This tutorial demonstrated a common and practical office scenario: batch extracting the Book ID number from the body of TXT files and using it to replace the original filename. With HeSoft Doc Batch Tool , the entire process only requires selecting the feature, importing files, setting the regex, choosing overwrite filename, and executing the process, to complete a task that originally required much repetitive manual work.
For users who frequently organize texts, doc, docx, pdf, Excel-exported data, or other office documents, the core value of batch processing tools is to proceduralize repetitive labor. As long as the file content structure is stable, regex can help you accurately locate key information, and the software executes it in batches. It is suggested to start with this article's example, getting familiar with rule settings using test files, then apply it to larger-scale TXT file organization tasks.