When a folder contains a large number of files starting with numbers, manually creating folders and dragging files one by one into categories is time-consuming and error-prone. This article uses file name prefixes like 101, 102, 103 as an example to explain how to use HeSoft Doc Batch Tool , employing the file name classification feature and regular expression rules to automatically organize large numbers of txt, doc, docx, pdf, and other files into corresponding folders by their name prefixes at once.
In daily office work, many files are not completely disordered. For example, sales orders, inspection reports, log texts, customer data, and project documents often have a string of numbers at the beginning of the file name: 101LON05417.txt, 101SYD26137.txt, 102NYC53821.txt, 103PAR08578.txt... These numbers may represent departments, projects, customers, regions, or batches. When the number of files is small, manually creating folders like 101, 102, and 103 and dragging files in is still acceptable; however, if there are hundreds or thousands of txt, Word documents (docx/doc), Excel spreadsheets (xlsx/xls), or PDF files in a directory, manual classification is not only slow but also prone to omissions and misplaced files.
The problem this article aims to solve is clear: using the batch file organization capabilities in office software, through wildcard concepts and regular expression rules, to batch-classify many files based on fixed prefixes in file names and automatically group them together. In the example, we want to sort files with identical first three digits into folders of the same name, for instance, files starting with 101 go into the 101 folder, files starting with 102 go into the 102 folder, and files starting with 103 go into the 103 folder.
The software in the screenshots is HeSoft Doc Batch Tool , which is positioned as a batch processing software for office scenarios, suitable for handling repetitive, rule-based file organization tasks. Below, we will explain step-by-step how to accomplish this, using screenshots from before processing, after processing, and the operation interface.
Applicable Scenarios: Which Files Are Suitable for Batch Classification by File Name Regular Expressions
The key to classifying by file name is that the file name must contain classification information that can be extracted. Common situations include:
- The first few characters of the file name are project numbers, such as 101, 102, 103, A01, B02.
- The file name contains customer codes, for example, Customer A_Contract.docx, Customer B_Quotation.xlsx.
- The file name contains region or store codes, such as SH_Daily.pdf, BJ_Daily.pdf.
- The file name contains batch numbers, dates, or department abbreviations, e.g., 202606_Statistics.xlsx, HR_Onboarding.doc.
- A large number of txt logs, scanned documents, and report files need to be archived by number prefix.
If your file names already have a unified structure like "101LON05417.txt", it is very suitable to use regular expressions to extract the first three digits. This way, there is no need to judge which category each file belongs to individually; the software will automatically create or use corresponding classification folders based on the file name matching results.
Preview of Results: Files Mixed Before Processing, Grouped by Number After Processing
Before Processing: Files starting with 101, 102, 103 are all in the same directory
From the pre-processing screenshot, it can be seen that the current directory contains txt files with various number prefixes. The first three digits of the file names are 101, 102, and 103, but they are all mixed in the same folder. Although the prefixed numbers highlighted by the red box can be identified by sight, manual filtering becomes very inefficient if the number of files continues to increase.

In this example, the classification basis for file names is very clear: take the first 3 digits of the file name. 101LON05417.txt, 101LON09060.txt, 101SYD26137.txt should be placed in the 101 folder; 102LON48897.txt, 102NYC53821.txt should go into the 102 folder; 103LON23328.txt, 103PAR08578.txt should go into the 103 folder.
After Processing: 101, 102, 103 folders are automatically generated
After processing is complete, you can see that three folders—101, 102, and 103—have been generated in the directory according to the numbers. Files with the same prefix are organized into the corresponding folders, making the file structure clearer and more convenient for subsequent searching, packaging, delivery, or archiving.

The efficiency advantage of this organization method is very obvious when the number of files is large. Actions that originally required repeated searching, selecting, and dragging can be completed with a single rule setup, which is especially suitable for office workers who process similar files regularly.
Operation Steps: Classifying by File Name Prefix Using HeSoft Doc Batch Tool
Step 1: Enter file organization and select "Classify files by file name"
After opening HeSoft Doc Batch Tool , select "File Organization" in the left function bar. In the right-side tool list, you can see functions like "Classify files by file name," "Classify files by extension," and "Batch create new folders based on existing folders." This time, we need to classify by the number prefix in the file name, so select "Classify files by file name."

The purpose of this step is to enter the functional module for organizing files by file name rules. It's not about simply distinguishing by extension like txt, docx, pdf, but generating classification criteria based on a certain segment of content in the file name. This function is more appropriate for scenarios where file name prefixes represent business numbers.
Step 2: Import the files to be processed and confirm the list records
After entering "Classify files by file name," the top of the interface provides entries like "Add files" and "Import files from folder." In the screenshot, files from the test directory on drive D have been imported. The list displays information such as serial number, name, path, extension, creation time, and modification time, and summarizes the record count at the bottom.

In this step, it is recommended to focus on three checks: first, whether all files have been imported; second, whether the file names conform to the expected rule; third, whether the extensions are the file types to be organized this time. The example shows txt files, but the same idea applies to office files like doc, docx, xls, xlsx, ppt, pptx, pdf, as long as the file naming rules are consistent.
If files that do not need processing are mixed into the list, you can organize them in the source folder first and then import, or use the delete operation provided by the interface to remove unwanted records. After confirming everything is correct, click "Next" at the bottom to enter the processing options settings.
Step 3: Select "Classify by custom regular expression" and enter the rule
On the "Set processing options" page, you can see various classification methods, such as classify by the first character, classify by the first number, classify by the first English letter, classify by the last few characters, classify by the first few characters, classify by characters within a custom position range, and "Classify by custom regular expression." In this example, to accurately extract the first three digits from the file name, select "Classify by custom regular expression."

Enter in the "Regular Expression" input box: ^\d{3}. The meaning of this expression is as follows:
- ^ means to start matching from the beginning of the file name.
- \d represents a digit character.
- {3} means to match exactly 3 consecutive digits.
Therefore, ^\d{3} will match 101 from 101LON05417.txt, 102 from 102NYC53821.txt, and 103 from 103LON23328.txt. The software will use the matched content as the classification name, thereby placing files with the same match result into the same folder.
If your file name prefix is not three digits, you can adjust it according to the actual situation. For example, the first two digits can use ^\d{2}, and a four-character project code can use ^\d{4}. If the beginning is English letters, you can use rules like ^[A-Za-z]+. After setting, keep the case conversion at its default state, and then click "Next."
Step 4: Set the save location and start processing
According to the interface flow, the third step is "Set save location," and the fourth step is "Start processing." This step requires specifying where to save the processed files. It is recommended to choose an empty directory or a dedicated output directory for easy result verification and to avoid mixing with the original files.
After confirming the save location, enter the start processing phase. The software will match each file name according to the previously set regular expression and organize files with the same match result into corresponding folders. For this example, it will eventually create folders like 101, 102, 103, and txt files with the same file name prefix will be centrally placed into the corresponding directories.
Common Questions and Notes
1. Why does the regular expression need to be written as a start-of-string match?
Because the classification basis in the example is at the very beginning of the file name. If only \d{3} is written, it might theoretically match three digits elsewhere in the file name; adding ^ explicitly requires extraction from the start of the file name, resulting in more stable results.
2. What happens if file names are not uniform?
If some file names do not start with three digits, they may not be classified as expected. Therefore, before batch processing, it is recommended to first review the file list to confirm the naming rules. For files with chaotic naming, they can be processed separately first, or a batch file rename function can be used to unify the naming rules.
3. Can Word, Excel, and PDF files be processed?
Yes. The example in this article uses txt files, but the classification basis comes from the file name and does not depend on the document content. Therefore, as long as the file name conforms to the rule, Word documents (docx/doc), Excel spreadsheets (xlsx/xls), PowerPoint files (pptx/ppt), PDF files, as well as images and text files, can all be organized using a similar method.
4. It is recommended to test with a small number of files first
Regular expressions are very flexible, but it is necessary to ensure the rules are written accurately. When using it for the first time, you can import a small sample of files to test the results first. After confirming the folder names and classification results meet expectations, then process all files.
Summary: Replace Repetitive Dragging with Rules to Improve File Organization Efficiency
The core value of batch classification by file name is delegating repetitive manual judgment and drag-and-drop actions to office software. For materials with regular file name prefixes, such as numbered files like 101, 102, 103, you just need to import the files into HeSoft Doc Batch Tool , select "Classify by custom regular expression," enter ^\d{3}, set the save location, and start processing. This quickly generates corresponding folders and completes the archiving.
If you frequently face a large number of txt, docx, doc, xlsx, pdf files that need to be categorized by project number, customer number, department number, or batch number, it is highly recommended to try this batch organization method using regular expressions first. It can reduce repetitive labor, lower the probability of human error, and transform file archiving from "dragging one by one" to "set it once, batch complete."