Batch Set Book ID as File Name for Text Files: TXT Rename Tutorial


Translation:EnglishFrançaisDeutschEspañol日本語한국어,Update Time:2026-07-10 06:35:05

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!

Many TXT files are downloaded or generated with default names like book1.txt or book2.txt, but contain valuable Book IDs internally. This article explains how to use HeSoft Doc Batch Tool and the "Rename Text Files Using Content" feature with regular expressions to batch extract Book ID numbers from each text file as filenames. The tutorial includes before-and-after effects, step-by-step instructions, regex configuration details, and notes to help users quickly organize their files.

In daily office work and data management, we often encounter files like this: a folder contains a batch of TXT files with similar names, such as book1.txt, book2.txt, book3.txt. You cannot determine the content just by the file names. However, upon opening a file, the first line or the beginning of the text contains a unique identifier, for example, Book ID:4829173056. If you later need to search, upload, check against a list, or archive files by identifier, these default file names become an efficiency bottleneck.

This article explains a very practical batch processing method: using wildcard regular expressions to batch read text file content and use the matched content as the new file name. In the example, we will extract the Book ID number from the TXT file, turning meaningless names like book1.txt into identifiable identifier names like 4829173056.txt.

The office software used in this article is the HeSoft Doc Batch Tool shown in the screenshots. Its purpose is not simply editing a single document but helping users batch process files, reducing the workload of repetitive clicking, copying, pasting, and renaming. For users who need to process large numbers of TXT, Word docx/doc, PDF, or other office files at once, this kind of batch tool can significantly improve organization efficiency.

Applicable Scenarios: Why Use File Content to Rename TXT Files

Renaming TXT files using their content is suitable for all situations where "file names are unreliable, but there is a reliable identifier inside the file." This method is very common, especially in the following types of work:

  • E-book Identifier Organization: File names are temporary serial numbers exported by the system, but the text body contains Book IDs, ISBNs, article IDs, etc.
  • Business Data Archiving: Each TXT file contains order numbers, contract numbers, or customer IDs, which need to be used for naming to correspond with an Excel checklist.
  • Collected Text Cleanup: Batches of scraped or exported text files have messy names, but the beginning of the text contains titles, IDs, or source fields.
  • Log and Report Management: The log body contains device IDs, task numbers, or date batches, and this information needs to be extracted as file names.
  • Standardized Naming Before Delivery: Project delivery requires that file names must use internal identifiers rather than temporary names like book1, new, copy, etc.

If you rely on manual renaming, the typical process involves opening the first file, copying the identifier, closing the file, and modifying the file name; then opening the second file and repeating the operation. This process seems simple, but when there are many files, it takes a lot of time. More importantly, manual copying and pasting can easily lead to mismatches, such as copying the identifier of file A but pasting it onto the name of file B. Using HeSoft Doc Batch Tool can delegate such mechanical operations to the software.

Effect Preview: From Book Serial Number to Book ID File Name

Before processing, there were 5 TXT files in the folder. Their names were all in the format of "book" plus a number: book1.txt, book2.txt, book3.txt, book4.txt, book5.txt. Such file names only indicate sequence and cannot reflect the actual file content.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

Opening one of the files, you can see the first line of the text is Book ID:4829173056. The numeric part indicated by the red arrow is the content we want to extract as the file name. Below it are English titles and text paragraphs, but this content is not suitable for file names because it is too long and lacks the stability of an identifier.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

After batch processing, the file names have changed to numeric identifiers composed of Book IDs, such as 1958436720.txt, 4829173056.txt, 6094728315.txt, 7305619482.txt, 8640295173.txt. Now, each file name corresponds to the identifier in the text, making subsequent searching and management more direct.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

From this result, it's clear this operation doesn't simply replace characters in the file name. Instead, the software opens and reads each text file, extracts a field based on rules in the content, and then batch-generates new file names. This is exactly the value of office software for batch processing files.

Operation Steps: Setting Up Batch Renaming in HeSoft Doc Batch Tool

Below, combining with operation screenshots, we'll explain step-by-step how to complete this task. To ensure accurate renaming results, it is recommended to first prepare a test folder, gather all the TXT files to be processed in one place, and then perform the batch import.

Step 1: Select 'Rename text files using file content' in the File Name tool

After opening HeSoft Doc Batch Tool , the left side is the function category navigation. After selecting the File Name category, tools related to file name processing are displayed in the main area. The screenshot shows multiple function cards, including finding and replacing keywords in file names, inserting text into file names, adding prefixes and suffixes to file names, etc.

This time, the item to click is the 8th: Rename text files using file content. The interface prompt explains that this function is for "batch using certain text from the text file content as the filename for that file." This statement is key, indicating it's suitable for extracting content from the TXT body rather than just processing the original file name.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

After selecting this function, you enter a step-by-step wizard. The step bar guides the user through selecting files, setting processing options, setting the save location, and starting the processing. The advantage of step-by-step operations is that the purpose of each step is clear, making it hard to miss critical settings.

Step 2: Add or import TXT files for batch processing

After entering the function page, the first step is Select records to process. In the upper right corner of the interface, you can see buttons like Add File, Import Files from Folder, Clear, and More. For a small number of files, you can use Add File; if all TXT files in an entire folder need processing, using 'Import Files from Folder' is more convenient.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

In the screenshot, 5 records have been imported. The list displays the serial number, name, path, extension, creation time, modification time, and actions. This information can confirm two things: first, the files are imported from the correct path; second, the extension is txt, meeting the processing target for "rename text files using file content."

If you find a file was added by mistake, you can use the delete icon in the action column of each row to remove it; if the entire list is wrong, you can click Clear and re-import. After confirming the number of records and files are correct, click Next at the bottom.

Step 3: Select 'Custom formula matched text' as the search area

The second step is Set processing options. The interface first requires setting the "Search Area." From the screenshot, there are two options: "First line text" and "Custom formula matched text." In this example, Custom formula matched text is selected.

image-Batch rename text content,change Book ID to file name,batch process TXT files,wildcard regular expressions

Why not just select 'First line text'? Because the complete first line content is "Book ID:4829173056". If the entire line is taken directly, the file name might include the "Book ID:" text; our goal is to keep only the numeric identifier that follows. Therefore, a more precise approach is to use a regular expression, letting the software extract only the needed part.

The expected outcome of this step is: instead of taking the whole line, the software will match the target text from each TXT file's content based on the regular expression you provide.

Step 4: Enter the regular expression to match the number after Book ID

In the regular expression input box, the screenshot shows the following entry:

(?<=Book ID:)\d+

The purpose of this regular expression is to match the consecutive digits following "Book ID:". For example, when the text contains Book ID:4829173056, the software's match result is 4829173056, not the entire text segment including the prefix.

A simple explanation:

  • Book ID: is the fixed text for positioning, telling the software that the target number appears after it.
  • \d+ represents a string of digits, suitable for matching identifier-type content.
  • (?<=...) is used to set a precondition, so the final result only retains the number itself.

In practical office work, regular expressions can be flexibly adjusted according to the text format. For example, if the file contains "Number: 4829173056", you need to write the matching rule around "Number:"; if it's "ID=AB20260506", you need to match a combination of letters and numbers. The point is not memorizing a specific expression, but first observing the stable format in the text, then writing a rule that can extract the target field.

Step 5: Select 'Overwrite entire file name' to make the identifier the new file name

In the lower part of the same interface, the "Position" can be set. In the screenshot, Overwrite entire file name is selected. This means the matched Book ID number will replace the original main body of the file name.

For example, if the original file name is book2.txt and the matched text is 4829173056, after processing it will become 4829173056.txt. The main file name is overwritten, but the extension remains .txt, so the file type does not change.

If your requirement is not a complete replacement, you can also choose to insert it to the left or right of the file name based on the position options in the interface. However, in this example, to make the file name retain only the Book ID, selecting 'Overwrite the entire file name' is the clearest approach.

Step 6: Continue to the next step to complete the save location setup and start processing

After completing the search area, regular expression, and position settings, click the Next button at the bottom of the interface. The step bar at the top shows that the subsequent steps are Set save location and Start processing. These two steps are used to confirm the output method and execute the batch task.

Since batch renaming affects file management results, it is recommended to back up the original folder or test the settings with a small sample of files before processing important files. Proceed with the full folder after confirming the output file names meet expectations.

Notes: Making Batch Renaming Results More Stable

1. First, confirm the text format is consistent

Regular expressions depend on text patterns. If some files write "Book ID:4829173056" and others write "BookID 4829173056", the same expression might not match all of them. Therefore, before batch processing, it's best to spot-check multiple TXT files to confirm the Book ID field format is consistent.

2. File names cannot contain illegal characters

This example extracts pure numbers, which generally avoids illegal character issues in file names. But if you extract titles, paragraphs, or other text, note that they might contain slashes, colons, question marks, and other characters unsuitable for file names. Identifier-type fields are usually more suitable for batch renaming.

3. Avoid extracting excessively long content

Using an entire title or text body as a file name can result in overly long file names, which are inconvenient for copying, syncing, and archiving. This example only extracts the Book ID number, which has a stable length and is suitable for mass naming.

4. It is recommended to back up before processing

The advantage of batch processing is speed, but it also means incorrect settings can affect multiple files simultaneously. It's advisable to copy a test directory first, confirm the regular expression, overwrite position, and processing results are correct, and then execute on the official folder.

5. Select the corresponding function for different file formats

The example in this article is for TXT text files. If you need to process Word files, pay attention to the "Rename Word files using file content" tool in the software, which applies to docx, doc, and other document scenarios; for PDF files, select the PDF-related content renaming function. Choosing the tool corresponding to the file type usually yields more stable processing results.

Common Questions: What issues might arise when extracting Book ID with Regex

Can the Book ID be processed if it's not on the first line?

As seen in the screenshot, this example uses "Custom formula matched text" rather than just taking the first line of text. Therefore, as long as the regular expression can match the target field within the text content, it can be extracted according to the rules. Actual effectiveness is still recommended to be tested with sample files.

If there is a space after the Book ID, does the expression need to be changed?

If the format changes from "Book ID:4829173056" to "Book ID: 4829173056", with an extra space after the colon, the original expression might not match as expected. In this case, the space must be accounted for in the rule. Adjust the expression based on the actual file content before batch processing.

What if multiple files extract the same identifier?

Renaming to the same file name can cause conflicts. It is recommended to choose highly unique fields as file names, such as Book IDs, order numbers, serial numbers, etc. If duplication is a concern, you can first verify the data source or test with a small batch of files.

Is it possible to keep the original book serial number?

The screenshot shows "Overwrite entire file name" is selected, so only the Book ID is kept after processing. If you wish to keep the original file name and append the Book ID, you can adjust the position using the "To the left of the file name" or "To the right of the file name" options in the interface. However, the goal of this article is to completely replace the original name with the Book ID.

Summary: Turning File Naming into an Automated Process with a Batch Processing Tool

Batch setting the Book ID from TXT files as the file name essentially converts manual repetitive operations into rules-based automated processing. The "Rename text files using file content" function provided by HeSoft Doc Batch Tool can batch import TXT files, extract target text from the content using regular expressions, and then overwrite or insert it into the file name according to the settings.

For office users who need to organize a large number of text files, this method significantly reduces the time spent opening files, copying identifiers, and manually renaming, while also lowering the chance of errors. It is recommended that you first prepare a few sample TXT files, set up a matching rule like (?<=Book ID:)\d+ following the steps in this article, and after confirming the results are correct, import the entire batch of files for processing. This way, you ensure accuracy while leveraging the efficiency benefits of batch file processing.


Keyword:Batch rename text content , change Book ID to file name , batch process TXT files , wildcard regular expressions
Creation Time:2026-07-10 06:34:49

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!