Too many files? How to group them by name rules? Use regex to batch sort them into corresponding folders
Translation:EnglishFrançaisDeutschEspañol日本語한êµì–´ï¼ŒUpdate Time:2026-06-29 06:56:55
When dealing with a large number of similarly named office files, if the first few characters of the file name represent a project, customer, or classification code, you can use regular expressions to automatically extract the code and group them. This article demonstrates in HeSoft Doc Batch Tool how to import files by "classify files by file name," select "classify by custom regular expression," and enter ^\d{3} to batch organize files starting with 101, 102, and 103 into corresponding folders, reducing the repetitive labor of manual sorting and moving.
When the number of files increases, organizing them becomes an inefficient but unavoidable task. Particularly after batch-downloading files from business systems, devices, email attachments, or collaboration platforms, filenames often contain fixed numbers, such as 101, 102, 103. During manual organization, we typically look at the filename prefix first and then decide which folder to place it in. Doing this a few dozen times is acceptable, but repeating it hundreds of times is a huge waste of time.
This article introduces a batch organization method more suitable for office scenarios: using HeSoft Doc Batch Tool to automatically group files based on rules in the filename. In the example, we will use the regular expression ^\d{3} to extract the first 3 digits of the filename and group files starting with the same digits together. Whether the files are txt text, Word documents docx/doc, Excel spreadsheets xlsx/xls, or PDFs, as long as the filenames meet the rule, you can refer to this approach.
Applicable Scenarios: Batch Grouping When Filenames Have Fixed Rules
Grouping by naming rules focuses on the filename itself, not the file content. As long as the filename reflects classification information, you can use tools for batch organization. The following situations are very common:
- Numbers at the start of the filename: such as 101LON05417.txt, 102NYC53821.txt, needing to be grouped by 101, 102.
- Customer code in the prefix: such as A001-Contract.docx, A001-Invoice.pdf, B002-Quote.xlsx, needing to be archived by customer code.
- Uniform project number naming: The project number is in the first few digits of the filename, followed by different types of documents.
- System exported files: Filenames have a fixed structure, but all are exported to the same directory.
- Summarizing multi-format materials: Under the same category, there are documents, spreadsheets, scans, and text files.
For these types of tasks, the positioning of HeSoft Doc Batch Tool is very clear: it is a batch processing software for office files, helping users reduce repetitive work. You don't need to create new folders one by one or determine file ownership individually; simply configure the naming rules and let the software complete the organization according to the rules.
Preview of Results: File Naming Pattern Before Processing
The image below shows the file list before processing. You can see that all files are mixed in the same directory, but the first 3 digits of the filenames carry classification significance. Red annotations respectively point out the prefixes 101, 102, 103. These are the basis for subsequent classification.

If organized traditionally, you would need to filter for files starting with 101 and move them first, then filter for 102 and move them, and finally process 103. As the number of categories increases, manual operation becomes more and more tedious. In contrast, a regular expression can define the action of "identifying the first 3 digits" clearly and once, applicable to all files meeting the rule.
Preview of Results: Files Moved into Corresponding Category Folders After Processing
After processing is complete, folders named after the classification results appear in the directory. In the example, three folders—101, 102, 103—were generated, indicating that the software has categorized the files based on the starting digits of the filenames.

This result is very suitable for subsequent management. For instance, when you need to view only files related to number 103, you can just go directly into the 103 folder; if you need to compress and send the 101 materials to a colleague, the files from 102 or 103 won't be mixed in. The goal of file organization is not just to "look neat," but to make subsequent searching and collaboration more efficient.
Steps: Using Custom Regular Expressions for Batch File Organization
Step One: Open the File Organization Feature
After starting HeSoft Doc Batch Tool , find File Organization in the left navigation bar. The right functional area displays multiple cards related to file organization; this time, select Classify files by name.

As seen in the screenshot, the feature description states it classifies all files by name in batches. In other words, it focuses on "what classification information is contained in the filename," making it very suitable for the archiving needs based on prefix numbers described in this article.
Step Two: Import Files to be Classified
After entering the feature, the first step is to select the records to be processed. At the top of the interface, there are operation entries like Add Files, Import files from folder, and Clear. If all files to be organized are in one folder, using "Import files from folder" is quicker; if you only want to process some of them, you can use "Add Files" to select.

After the import is complete, the files are listed in a table. You can check the file name, path, extension, creation time, and modification time in the table. In the screenshot's example files, they are located in D:\test\ directory, the extension is txt, and the record count is 20. After confirming the records to be processed are correct, click Next at the bottom.
Step Three: Choose Classification by Custom Regular Expression
After entering "Set processing options," you can see multiple classification methods. For simple rules, you can choose to classify by the first character, by the first number, or by the first few characters. However, this example aims to clearly match the consecutive 3 digits at the start of the filename, so choose Classify by custom regular expression.

Then, enter the following in the "Regular Expression" input box:
^\d{3}
This expression is very suitable for the current example:
- ^ locks the match to the start of the filename, preventing matches with numbers later on.
- \d represents a digit character.
- {3} means matching 3 digits.
Therefore, the file 101TYO08638.txt will be identified as category 101, 102TYO76564.txt as category 102, and 103SYD61045.txt as category 103. The software will organize the files into the corresponding locations based on the identified category value.
Step Four: Keep Default Case Settings as Needed
At the bottom of the same page, there is a "Letter case conversion" setting. Since the classification field in this example consists of numbers, the default settings are fine. If your file classification prefix contains English letters, such as abc001, ABC002, then whether to convert case will affect the classification results. To avoid files from the same category being split into multiple folders, it is recommended to unify the naming rules before processing or select the appropriate case handling method here.
Step Five: Set Save Location and Start Processing
After clicking Next, the process proceeds to "Set save location". It is suggested to save the processing results to a new directory, which facilitates comparing the before and after results and protects the original files. After confirming the save location, proceed to "Start Processing".
Upon completion of the batch processing, open the output directory to check the results. Under normal circumstances, you will see folders like 101, 102, 103, with files sharing the same prefix already concentrated within the corresponding folder. If the processing results meet expectations, you can use these classified folders for subsequent archiving, backup, compression, or sending.
Frequently Asked Questions and Considerations
1. Why use ^\d{3} instead of directly inputting 101?
If you only input a fixed 101, it targets only one specific number. The advantage of using ^\d{3} is that it automatically matches any starting 3-digit number, including 101, 102, 103, and potential future numbers like 104, 205, 999. This makes the rule more general and more suitable for batch processing.
2. What if the filename prefix isn't 3 digits?
Adjust the expression based on the actual naming rule. For instance, if the classification code is the first 2 digits, change it to match 2 digits; if the first 4 digits are the year or project number, match 4 digits. The core idea is to have the expression accurately extract the classification field, rather than rigidly copying the example.
3. Will numbers in the middle of the filename affect grouping?
This example uses ^, which means matching only from the start of the filename. Therefore, even if there are other numbers later, they won't serve as the basis for classification. This is also one of the advantages of using regular expressions: you can clearly define the match position, reducing misclassification.
4. What preparations are needed before batch classification?
It is advisable to do three things first: First, confirm all files to be processed have been imported; second, confirm the filename rules are consistent; third, back up important data or output to a new directory. Batch processing can significantly improve efficiency, but incorrect rule settings can also impact results in batch, making preliminary checks very important.
5. Is it suitable for mixed Word, Excel, and PDF files?
Yes, it is suitable. This scenario classifies by filename, not by file content. As long as the filenames have the same starting rule, 101-Contract.docx, 101-Details.xlsx, and 101-Scan.pdf can be grouped into the same category. This cross-format organization capability is very practical for real office document archiving.
Summary: Improving File Organization Efficiency with Regex Rules
When a large number of files need to be grouped by naming rules, the most important thing is to find a stable classification field. In this article's example, the first 3 digits of the filename serve as the classification field; by selecting "Classify files by name" in HeSoft Doc Batch Tool and then using the custom regular expression ^\d{3}, files starting with prefixes like 101, 102, 103 can be batch-organized into corresponding folders.
Compared to manual filtering and moving, this method is more suitable for processing large volumes of office files, especially for project materials, client documents, system export files, and historical file archiving. It is recommended that before organizing files next time, you first observe whether there are patterns in the filenames; if so, let a batch processing tool handle the repetitive operations for you, freeing up time for more important work.
Keyword:Group files by naming rules , organize files using regular expressions , and batch move files to folders