Batch rename txt file names to specified fields within the files: Wildcard regular expression renaming method


TranslationEnglishFrançaisDeutschEspañol日本語한국어Update Time2026-07-10 06:32:58

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

If a batch of TXT files have meaningless names but each file contains fixed fields, such as the numeric code following "Book ID", you can use office software to batch rename them. This article focuses on the need to "batch rename TXT files to a specified field within the file", explaining how to import text files into HeSoft Doc Batch Tool , use regular expressions to match the number after Book ID, and choose to overwrite the entire filename, ultimately batch-changing temporary filenames like book1.txt to the corresponding numeric filenames.

The more files you have, the more important naming becomes. Many people find when organizing txt files that the filenames in a folder often don't represent the actual content: book1.txt, book2.txt, book3.txt appear sequential, but you can't tell which file corresponds to which real identifier. Only after opening a file do you discover that the information which should be used for naming is written in the body, for example: Book ID:4829173056. If there are only a few files, manual renaming is acceptable; but with hundreds or even more files, repeatedly opening, copying, pasting, and renaming becomes very inefficient.

This article introduces a highly practical batch processing method for office scenarios: utilizing the "Rename Text Files Using File Content" feature of HeSoft Doc Batch Tool , combined with regular expressions, to batch extract specified fields from within txt files and use them as filenames. You can think of it as letting the software automatically read each text file, find your specified content, and then complete the batch renaming.

Applicable Scenario: Batch Converting Fields Inside Files into Filenames

This processing method is suitable for materials where the internal file content structure is relatively fixed. For example, every txt file has a Book ID in the same format; each exported document has a fixed format number; the beginning of every record contains a project ID, customer ID, device ID, contract number, or order number. As long as the target field can be located via wildcards or regular expressions, it can be extracted in batch.

It is especially suitable for the following office tasks: organizing electronic book text materials and using Book IDs as filenames; organizing system-exported txt records and using order numbers as filenames; organizing device logs and using device numbers or serial numbers as filenames; organizing customer text archives and using customer IDs as filenames; organizing research materials and using sample numbers as filenames.

Compared to traditional manual operations, the advantages of this type of batch file processing are very clear: rules are set once and executed uniformly across multiple files; it reduces errors and omissions caused by manual copy-pasting; file naming formats become more consistent; and once complete, files are easier to search, sort, archive, and hand over.

Effect Preview: Comparison Before and After Renaming

Before Processing: Filenames Cannot Reflect the Book ID in the Body

The file list before processing shows the current directory contains book1.txt, book2.txt, book3.txt, book4.txt, and book5.txt. These names are only suitable for temporary viewing and not for long-term archiving. For instance, if you want to find the file with Book ID 4829173056, you cannot directly determine which one it is from the filename.

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

After opening one of the txt files, you can see the first line of the body contains Book ID:4829173056. The red arrow in the screenshot points to this identifier, indicating it is exactly the content we want to extract and use for naming.

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

After Processing: Each Filename Becomes the Corresponding Numeric ID

After batch processing is complete, the names in the file list have become 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, and 8640295173.txt. This means the software extracted the corresponding ID from each text file and overwrote it as the new filename.

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

Such filenames are more suitable for subsequent management. Whether searching via Windows, sorting by name, or comparing with IDs in a spreadsheet, they are more intuitive than names like book1, book2.

Steps: Batch Renaming Text Files Using Wildcard Regular Expressions

Step 1: Open File Name Category, Select the Corresponding Function

In the main interface of HeSoft Doc Batch Tool , the left navigation shows several office file processing categories. Since this task involves modifying filenames, select File Name. The function cards on the right display multiple tools related to file naming.

This time, click "Rename Text Files Using File Content". From the interface prompt, you can see this function is used to batch-use certain text from the content of text files as their filenames, precisely matching the need to "extract fields from txt body and rename."

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

The key here is selecting the right tool. If you only want to replace certain characters in the original filename, you can use find-and-replace functions; but if the new filename comes from the file's internal content, you should use the text content renaming feature demonstrated in this article.

Step 2: Add Files or Import Files from a Folder

After entering the function page, the first stage is Select the records to be processed. Above the interface provides Add Files and Import Files from Folder. If the number of files is small, you can add files directly; if the files are all in the same directory, importing from a folder is more convenient.

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

After the import is complete, the list displays the file name, path, extension, creation time, and modification time. The screenshot shows 5 txt files have been imported, with paths from D:\test\book1.txt to D:\test\book5.txt. After confirming the record count, extensions, and paths are correct, click Next at the bottom.

The expected result of this step is: all txt files needing renaming based on content are in the task list, without any irrelevant files. Confirming the file list before batch processing is very important, as the software will process items sequentially based on this list later.

Step 3: Set the Search Area to Custom Formula Matched Text

After entering "Set Processing Options," first set the search area. The screenshot shows Text matched by custom formula is selected, rather than directly selecting the first line of text. This is because the first line contains the characters "Book ID:" besides the target number. If you directly take the whole line, the filename might include unwanted text; using a regular expression allows extracting only the numeric part.

Enter in the regular expression input box:

(?<=Book ID:)\d+

image-Batch renaming of txt files,field renaming within files,batch renaming with wildcard regular expressions

The meaning of this rule is: find the consecutive digits located after "Book ID:". For example, if the text content is "Book ID:4829173056", the match result is 4829173056. This syntax is suitable for text formats where the field prefix is fixed, followed by a numeric identifier.

Step 4: Choose to Overwrite the Entire Filename

On the same settings page, you also need to set where to place the extracted content in the filename. The screenshot shows Overwrite the entire filename is selected. This means the original "book1", "book2" will be completely replaced by the numbers matched by the regular expression.

If your goal is to keep the original name and add the ID on the left or right side, you can choose other positions; but since this example changes filenames to specified internal fields, choosing to overwrite the entire filename is the most direct. After processing, you will get results like 4829173056.txt, and the extension .txt will be preserved.

Step 5: Proceed to Save Location and Start Processing Stage

After completing the rule settings, click Next. The interface flow shows subsequent steps for "Set Save Location" and "Start Processing." Before actual execution, it is recommended to first confirm the save-related settings and check if the regular expression matches the sample text exactly.

Once processing starts, HeSoft Doc Batch Tool will follow the imported list, read each txt file's content, use the set regular expression to find the numbers following the Book ID, and apply the result to the filename. After processing is complete, return to the folder view to see the filenames have been batch-replaced with identifiers.

Explanation of Regular Expression and Wildcard Logic

Many users understand both wildcards and regular expressions as "matching text using rules." In batch renaming, their core purpose is the same: not to manually specify each filename, but to use a single rule to find different target content within each file.

The (?<=Book ID:)\d+ used in this example is a more precise syntax. It does not match the entire line, nor the "Book ID" text itself, only capturing the numbers after it. This method avoids redundant prefixes in the filename, making the processed results cleaner.

If your text is not purely numeric but contains letters, hyphens, or underscores, you will need to adjust the matching rule based on the actual field. It is recommended to first open a few sample files, observe if the target fields are consistently in the same position, have spaces, or have consistent letter casing, before deciding which regular expression to use.

Common Questions or Precautions

1. Field Format Must Be as Uniform as Possible

Batch processing relies on rules. If some files write "Book ID:", others "BookID:", and some have a space after the colon, a uniform rule might fail to match all of them. It is best to spot-check samples before processing and, if necessary, unify the text format first.

2. Not Recommended to Process All Important Files Initially

For important materials, it is recommended to copy a test folder and verify the results with a small number of files first. Only after confirming the renaming effect is correct should you process the complete folder. This is a good habit to follow for all batch file processing tasks.

3. Pay Attention to Duplicate Filenames and Illegal Characters

If two files extract the same identifier, it may cause a filename conflict. Also, if the extracted content is title-like text, it might contain characters not allowed in Windows filenames. This example extracts pure numbers, so the risk is low.

4. Confirm It Is a Text File, Not Word or PDF

The feature used in the screenshots is "Rename Text Files Using File Content," suitable for text files like .txt. If processing Word documents, common extensions include .docx, .doc; for PDF files, you should choose functions related to Word or PDF content renaming, not the text file function.

Summary: Batch Convert Fields from txt Body into Filenames

Using a Book ID example, this article demonstrated how to batch extract specified fields from multiple txt files and overwrite them as new filenames. The entire process includes selecting "Rename Text Files Using File Content," importing the txt files, filling in the regular expression, choosing to overwrite the entire filename, proceeding to the save location, and starting the processing.

For office users who need to organize a large number of text files long-term, this method can significantly reduce repetitive operations, make filenames more standardized and searchable, and lower errors caused by manual copy-pasting. It is recommended that you first select a few sample files to verify the regex rule, confirming the before-and-after effects match expectations, before applying it in batch to the complete folder.


KeywordBatch renaming of txt files , field renaming within files , batch renaming with wildcard regular expressions
Creation Time2026-07-10 06:32:42

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

Related Articles

Don't see the feature you want?

Provide us with your feedback, and after evaluation, we will implement it for free!