When the names of a large number of files contain fixed-position numbers, regions, project codes, or department codes, manually creating folders one by one and moving files into them is very time-consuming. This article, using characters 4 to 6 in the file name as an example, introduces how to use HeSoft Doc Batch Tool to automatically sort a large number of txt files into corresponding folders based on the specified range of characters in the file name. This method also applies to common office file formats such as doc, docx, xls, xlsx, and pdf, making it suitable for office scenarios requiring batch organization of materials, orders, reports, logs, or project files.
In daily office work, we often encounter batches of files that need to be categorized based on a specific segment of characters in their filenames. For example, filenames like "128LON75957.txt," "200LON66460.txt," "213TYO11946.txt," and "230SYD60610.txt," where the 4th to 6th characters represent the city, store, project team, or business code respectively. If there are only a few files, manually checking the filename and dragging them into folders is acceptable; however, when the number of files reaches dozens, hundreds, or even thousands, manual sorting is not only inefficient but also prone to misplacing files.
The problem this article aims to solve is: how to batch categorize numerous files based on a fixed range of characters in their filenames. Utilizing the file organization capability of the office software " HeSoft Doc Batch Tool ", you can extract characters from specified positions in filenames, automatically create corresponding category folders, and then move the files into the appropriate directories. This significantly reduces repetitive work and is particularly suitable for processing txt logs, Word docs/docx, Excel spreadsheets xls/xlsx, PDF documents, images, or other files with rule-based naming.
Applicable Scenarios: Which Files are Suitable for Categorization by Fixed Character Range
The prerequisite for categorizing by a fixed range of characters in filenames is that the file naming follows a stable rule, and the characters used for classification appear in the same positions. For example, "the first three digits are a serial number, the 4th to 6th characters are the city code, followed by the order number"; or "the first two digits are the department code, the 3rd to 5th are the project code, followed by the date." As long as the position of the classification character in the filename is fixed, this method can be used for batch filing.
Common scenarios include: organizing logistics files by city codes, such as LON, NYC, PAR, SYD, TYO; organizing reimbursement forms, contracts, and notices by department code; organizing Word docx/doc or PDF documents by project code; organizing Excel xlsx/xls reports by customer ID; organizing txt log files by device number or production line number. Compared to categorizing by extension, this method is more suitable for organizing materials that share the same file type but belong to different categories.
Note that the file extension in this article's example is txt, but the operational logic is not limited to txt. As long as the filename itself contains identifiable fixed-position characters, files like Word, Excel, PowerPoint, PDF, and images can also be batch organized using the same approach.
Effect Preview: Files Mixed in a Single Directory Before Processing
Before processing, all files are stored in a single folder. The filenames consist of numbers, a three-letter code, and a subsequent serial number, such as "128LON75957.txt," "213TYO11946.txt," "230SYD60610.txt," "378PAR56483.txt," etc. In the screenshot, the three-letter characters in the middle of the filenames are highlighted with a red line; these characters serve as the basis for this categorization.

From the screenshot, it's clear that manual organization would require identifying codes like LON, TYO, SYD, PAR, NYC in each filename, creating the corresponding folders individually, and then moving the files into them. The more files there are, the more repetitive the judgment and dragging becomes. For batch file processing in an office environment, this type of repetitive task is ideal for automation by a tool.
Effect Preview: Category Folders Automatically Generated After Processing
After processing, the originally mixed files are automatically categorized, and multiple folders named after the classification characters appear at the target location, including LON, NYC, PAR, SYD, and TYO. Files with the same characters in the specified range of the filename are placed into each folder. For example, files with the 4th to 6th characters being LON are placed in the LON folder, and those with SYD in the same position are placed in the SYD folder.

This outcome is very suitable for subsequent handover, archiving, compressed sending, or departmental processing. Users do not need to copy and paste files individually or manually create multiple folders; the software completes the batch organization based on filename rules.
Operating Steps: Using HeSoft Doc Batch Tool to Categorize by Filename Range
Step One: Enter the File Organization Function and Select Categorize by Filename
Open HeSoft Doc Batch Tool , and select "File Organization" from the left function bar. In the right function card, you will see the function "Categorize Files by Filename." The purpose of this function is to batch organize files based on certain characters or rules within the filename.

Entering this function initiates a step-by-step processing workflow. For first-time users, this wizard-style interface is quite clear: first select the files to process, then set the categorization rule, then set the save location, and finally start processing.
Step Two: Import the Files to Categorize and Check the List
On the "Categorize Files by Filename" page, first import the files you need to process. The upper part of the interface provides options like "Add Files" and "Import Files from Folder," which you can choose based on the actual situation. If the files are already gathered in a single directory, importing from a folder is usually more convenient; if you only need to process a subset, you can add files individually.

After importing, the software displays a list with information such as sequence number, name, path, extension, creation time, and modification time. Checking this list is crucial: confirm that the list contains the exact files you intend to categorize, verify that the filename rules are consistent, and ensure the extensions and paths are correctly selected. The screenshot shows 20 records, all with the txt extension, located in a test directory on the D drive. After verifying, click "Next" at the bottom to proceed to processing options.
Step Three: Select "Categorize by Characters in Custom Position Range"
In the "Set Processing Options" step, you need to choose the categorization method. Since the requirement is to extract a fixed range of characters from the filename—specifically the three-letter codes at positions 4 through 6—you should select "Categorize by Characters in Custom Position Range." This option is applicable when the classification identifier is located at a fixed position in the filename.

The screenshot shows the "Categorization Method" area provides various methods, such as categorize by first character, by first digit, by first English letter, by the first few characters, or by custom regex. In this example, we don't need to identify the first character or categorize by extension, but rather extract a segment of characters from the middle. Therefore, selecting "Categorize by Characters in Custom Position Range" is more accurate.
Step Four: Fill in 4:6 in the Range Field
After selecting the custom position range, enter "4:6" in the "Range" input field. This signifies that characters from the 4th to the 6th position of the filename will be used for categorization. Taking "128LON75957.txt" as an example, excluding the extension, the first three digits are 128, and the 4th to 6th characters are LON, so the software will categorize this file under LON. Similarly, for "213TYO11946.txt," the characters at positions 4 to 6 are TYO, so it will be placed in the TYO folder.
When specifying the range, it's essential to carefully confirm the position calculation against the actual filenames. It is recommended to manually count the characters of a typical filename to verify the range to be extracted. For "128LON75957," 1 is the 1st, 2 is the 2nd, 8 is the 3rd, L is the 4th, O is the 5th, and N is the 6th, hence the range is written as 4:6. If the filename has leading spaces, symbols, or extra codes, the range might need adjustment.
Step Five: Maintain or Set Letter Case Conversion
Below on the same page, you can see the "Letter Case Conversion" option, which includes Default, Convert to Uppercase, and Convert to Lowercase. The example shows "Default" is selected. If the classification characters in the filenames are already consistently uppercase, like LON, NYC, PAR, keeping the default is fine.
If your actual files contain inconsistencies like "lon," "Lon," and "LON," you can choose to convert them all to uppercase or lowercase based on business needs to ensure similar files are grouped into the same folder. The example screenshots use the default settings because the classification codes in the filenames were already unified.
Step Six: Set the Save Location and Start Processing
After completing the categorization rule settings, click "Next" to proceed to "Set Save Location." The purpose of this step is to tell the software where to save the organized folders and files. For easier verification, it is recommended to select an empty directory or create a new dedicated output directory to avoid confusion with the original files.
Once the save location is confirmed, proceed to "Start Processing." The software will, based on the previously set range rule, extract the 4th to 6th characters from each filename, create category folders named after these characters, and finally sort the files into the corresponding folders. After processing, you will see the folders LON, NYC, PAR, SYD, and TYO.
Common Questions and Notes
1. What if Filename Lengths are Inconsistent?
Categorizing by a fixed position range requires stable content at the specified filename positions. If some filenames are too short, or their 4th to 6th characters are not the classification code, these files might not be categorized as expected. Therefore, it is necessary to check the naming rules before batch processing and unify the filename format if needed.
2. Is the Range Based on the Filename or the Full Filename with Extension?
From the example, the classification basis comes from the main filename before the extension. In practice, it is best to use the "Name" field in the file list as a reference and test with a few files first. For files with different extensions like docx, xlsx, or pdf, the key remains the fixed characters in the main part of the filename.
3. Where Do the Folder Names Come From After Categorization?
The folder names are derived from the extracted characters. For instance, when the range is 4:6, if the characters at positions 4 to 6 in a filename are LON, a LON folder is generated or used; if the result is PAR, the file is placed in the PAR folder. This ensures the classification results align with the original naming convention.
4. Can This Be Used for Word, Excel, and PDF Files?
The same method can be referenced. Whether it's txt logs, Word docs/docx, Excel xls/xlsx spreadsheets, or PDF documents, as long as the filename contains classification characters at fixed positions, you can use this filename-based categorization approach for organization.
Summary: Leave Repetitive Categorization to Office Software
Batch categorizing files by a fixed range of characters in their filenames is a highly practical file organization method. It is well-suited for handling office documents with clear naming rules, large quantities, and a need for archiving by code or identifier. Using HeSoft Doc Batch Tool , you just need to import the files, select "Categorize by Characters in Custom Position Range," fill in the range "4:6," set the save location, and start processing. This automatically sorts a jumbled set of files into folders like LON, NYC, PAR, SYD, and TYO.
If you frequently need to organize order files, log files, project documents, report materials, or customer files, it is advisable to first observe if the filenames contain classification characters at fixed positions. Once the rule is clear, you can use a batch processing tool to replace manual drag-and-drop, significantly reducing repetitive work and improving the accuracy and efficiency of file archiving.