Many TXT files have key information not in the file name but hidden at the beginning of the content or in fixed fields, such as the numeric ID after "Book ID". This article uses HeSoft Doc Batch Tool to demonstrate an efficient method: first import multiple text files, then use regular expressions to match the IDs within the content, and finally overwrite the matched results as new file names. The tutorial includes before-and-after effects, key parameter settings, and notes, making it suitable for office users who need to organize large amounts of TXT documents, numbered files, or text materials.
In daily office work and document organization, text files often come from batch downloads, system exports, script generation, or data conversion. Their filenames might just be book1.txt, book2.txt, book3.txt, revealing no useful information on the surface; however, upon opening the files, the body contains very critical numbers, such as "Book ID:4829173056". If you need to archive these files by these numbers, the traditional method is to open each TXT file one by one, copy the number, return to the folder, and paste to rename. This is manageable when there are few files, but becomes typical repetitive labor when there are many.
The method introduced in this article uses the "Rename Text Files Using File Content" feature in the office software " HeSoft Doc Batch Tool ", combined with wildcard logic and regular expression rules, to batch extract specified content from TXT file bodies and use the extracted results as filenames. The example will extract the Book ID number from the text, transforming multiple TXT files from meaningless sequential names to identifiable numbered names in one go.
Applicable Scenario: Numbers in the Body, but Filenames are Hard to Manage
This type of batch renaming requirement is common in office environments. As long as the file content has a fixed format, you can consider using rule-based methods to extract content and then generate filenames in batches. For example:
- The first line of text documents contains a Book ID, and you need the numbers following the Book ID to serve as the txt filename.
- Articles, reports, records, and description documents contain unique numbers, and you wish to archive them uniformly by number.
- Downloaded files have temporary sequential names, but the body contains the actual title, customer ID, or project ID.
- You need to extract content like "ID: number", "编号: number", or "Code: alphanumeric combination" from a large number of text files.
- You hope to reduce the time wasted on manual renaming, copying and pasting, and repeatedly opening files.
This tutorial uses TXT as an example, focusing on batch renaming of text files. If you are dealing with Word documents, you can pay attention to doc, docx, and other Word-related tools; for PDFs, you should use the corresponding feature for renaming PDFs by content. Different file formats have different structures, and choosing the right tool can prevent processing failures.
Effect Preview: From book Sequential Names to Book ID Number Names
Before Processing: TXT Names in the Folder Have No Business Meaning
Before processing, the folder has 5 text files named book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. Such names only indicate the number and order of files, making it impossible to tell which book, record, or number each file corresponds to.

Opening one of the text files, you can see the top of the body contains "Book ID:4829173056". Here, 4829173056 is the key information more suitable as a filename. In other words, there is a clear relationship between the filename and the file content: the new filename should come from the Book ID field in the body.

After Processing: Filenames Uniformly Changed to Extracted Number IDs
After the batch process is complete, the names in the file list have changed to 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt, etc. Each filename comes from the Book ID number in the corresponding TXT body, making folder browsing, searching, and verification more intuitive.

The value of this processing effect lies in not needing to manually confirm file content one by one or copy and paste numbers. As long as the rules are consistent, the software can complete text content extraction and file renaming in batches as set.
Operation Steps: Using HeSoft Doc Batch Tool to Complete TXT Batch Renaming
Step 1: Select the Text Content Renaming Feature in the File Name Tool
After launching HeSoft Doc Batch Tool , go to the "File Name" category in the left navigation. This category contains multiple features related to filename processing, such as find and replace, insert text, add prefix/suffix, etc. This time, we need to extract values from text content, so select "8. Rename Text Files Using File Content".

From the feature card's description, it's clear that it is used to batch-capture certain text from text file content to serve as that file's filename. That is, it doesn't simply modify existing filenames but generates new names after reading TXT content, making it very suitable for the Book ID extraction scenario in this article.
Step 2: Add Files or Import Files from a Folder
After entering the feature, the first step is to "Select records to be processed". The top right of the interface provides two entry points: "Add File" and "Import Files from Folder". If you are only processing a few specified files, click "Add File"; if the files are all in the same directory, using "Import Files from Folder" is more convenient.

After importing, the table will display the file name, path, extension, creation time, and modification time. The screenshot shows that 5 txt files have been added to the list, with the path located in the D drive test directory. The main purpose of this step is to confirm whether the scope of files to process is correct. Because batch renaming affects multiple files, before proceeding to the next step, you should check for any extra, missing, or mistakenly imported irrelevant files.
After confirming they are correct, click the "Next" button at the bottom of the page to enter the rule settings. Up to this point, the software has only established a to-do list and has not actually modified any filenames yet.
Step 3: Select "Text Matched by Custom Formula" as the Lookup Area
In the second step, "Set Processing Options", you first need to decide where the filename comes from. The "Lookup Area" in the interface offers different choices; for this example, select "Text matched by custom formula". This setting is crucial because we do not want to use the entire text as the filename, nor simply take all of the first line. Instead, we need to extract a specific segment of numbers matching a rule from the body.

If "First line text" were selected, the new filename might contain the complete "Book ID:4829173056". However, in actual archiving, we usually only need the numeric ID, preferring not to include the field name and colon in the filename. Therefore, using custom matching makes the filename cleaner and more uniform.
Step 4: Enter the Regular Expression to Match the Number After Book ID
Enter the following in the "Regular Expression" input field:
(?<=Book ID:)\d+
This rule is composed of two parts. The first part (?<=Book ID:) indicates that the position before the match must be "Book ID:"; the second part \d+ represents consecutive digits. The combined effect is: only extract the digits after "Book ID:".
Taking the content in the screenshot as an example, the text contains "Book ID:4829173056"; the software will match 4829173056 and use it for renaming. This avoids writing "Book ID:" into the filename and ensures the extracted number is the one after the target field, not digits from other parts of the body.
If your actual text format is different, you can modify the expression following the same logic. For instance, if the field prefix is not "Book ID:" but "Order No.:" or "编号:", you need to replace the fixed text part in the expression with your actual field. When using regular expressions, the most important thing is to first observe the sample file format before writing the matching rule.
Step 5: Set the Matching Result to Overwrite the Entire Filename
In the "Position" area, you can choose where to place the matched text in the filename. In the example, "Overwrite the entire filename" is selected, meaning the original filename body will be completely replaced by the extracted number. After processing, book2.txt will become 4829173056.txt, not 4829173056book2.txt or book24829173056.txt.
If your business requires keeping the original filename, you can also choose to insert it on the left or right based on the options provided in the interface. However, the goal of this example is to have the filename consist entirely of the Book ID, so "Overwrite the entire filename" is more aligned with the archiving requirement.
Step 6: Set the Save Location and Execute the Batch Process
After completing the matching rule and filename position settings, continue clicking "Next". The interface flow shows subsequent steps for "Set save location" and "Start processing". In the save location step, choose the output location according to your actual work habits; then proceed to the start processing step to let the software execute the batch rename.
After the process is finished, go back to the target folder to view the results. Now, the originally meaningless names like book1.txt, book2.txt, etc., have become the digital names corresponding to the Book ID in the body. The entire process eliminates the need to open files one by one or manually copy numbers.
Common Questions and Notes: Making Batch Renaming More Stable
1. What could be the reason if the regular expression matches no content?
The most common reason is that the text format is inconsistent with the expression. For example, the expression is written as "Book ID:", but the file actually has a Chinese colon "Book ID:", or there is an extra space in "Book ID: 4829173056". In such cases, you need to adjust the rule according to the actual text content.
2. If multiple numbers appear in the body, will it extract the wrong one?
The advantage of regular expressions is that they can limit the context. This example uses "Book ID:" as a precondition, only extracting the number following that field, rather than randomly grabbing all numbers from the body. Therefore, when writing rules, try to use stable field name prefixes to avoid rules that are too broad.
3. Can filenames contain characters like colons or slashes?
Windows filenames have restrictions on certain characters, such as colons, slashes, and backslashes are usually not allowed directly in filenames. This example only extracts numbers, so it won't encounter illegal character issues. If you are extracting title text, pay attention to whether the title contains symbols unsuitable for filenames.
4. Why is it recommended to test on a small scale before batch processing?
Batch file processing is very efficient, but if the rules are set up inaccurately, they can also quickly affect multiple files. Therefore, it is recommended to first import a small number of samples for testing, such as 5 or 10 TXT files, confirm the output results fully meet expectations, and then process the complete folder. For important documents, it's best to keep a backup first.
5. Can this process be used for doc, docx, or PDF?
This article demonstrates the processing flow for text files (TXT). In the HeSoft Doc Batch Tool interface, you can also see related feature entries for renaming Word files and PDF files by content. However, formats like doc, docx, pdf are different from plain text. You should choose the corresponding Word tool or PDF tool and it is not recommended to mix them.
Summary: Automating File Naming by Extracting Content with Rules
When the useful information of a large number of TXT files is hidden in the body, manual renaming is an inefficient and error-prone task. Through HeSoft Doc Batch Tool , you can first batch import text files, then use regular expressions to target the number after "Book ID:", and finally overwrite the filename with the matching result. The entire process is clear, reusable, and especially suitable for organizing text documents with fixed formats.
If you are currently dealing with a batch of txt files with chaotic names, it's recommended to open a few samples first to observe the field patterns, then follow the steps in this article to set up "Text matched by custom formula" and the regular expression. Once you confirm the effect is correct, you can delegate the repetitive task of file renaming to the software, thus saving time for more valuable content review, archiving, and analysis.