Many office document file names include fixed codes, such as city codes, department codes, customer numbers, or project abbreviations. If these codes are in the middle of the file names, manual sorting is extremely inefficient. This article demonstrates how to use HeSoft Doc Batch Tool to batch sort files by characters 4 through 6 in the file name, automatically organizing files containing codes like LON, NYC, PAR, SYD, TYO into corresponding folders. This is suitable for batch archiving of materials such as txt, doc, docx, xls, xlsx, pdf, and others.
In file archiving work, a common scenario often arises: there are many files, and the file names appear complex, but a specific segment of characters within them is critical. For example, 128LON75957.txt, 200LON66460.txt, 213TYO11946.txt, 230SYD60610.txt, 378PAR56483.txt. The characters like LON, TYO, SYD, PAR in the middle of these file names often represent cities, branches, clients, projects, or business types.
If you need to sort these files into different folders based on these codes, the traditional approach involves first examining the file names, then manually creating folders like LON, TYO, SYD, PAR, and finally dragging and moving files into them one by one. This is manageable when there are few files, but a large number easily leads to issues like missed sorting, incorrect sorting, and duplicate moves. This is especially true for roles in administration, HR, finance, operations, and project management, which frequently need to process batches of exported documents, reports, vouchers, images, or text records, where manual sorting consumes a significant amount of time.
This article will introduce a more office-scenario-friendly method: using HeSoft Doc Batch Tool to automatically categorize files based on a fixed range of characters in the middle of their names. In this example, we will extract characters from the 4th to the 6th position of the file name as the basis for categorization, ultimately creating folders like LON, NYC, PAR, SYD, TYO, achieving the effect of batch-creating category folders and archiving files.
Suitable Scenarios: Most Suitable When There is a Fixed Code in the Middle of the File Name
The premise for categorizing by a middle code in the file name is that the file naming follows a certain pattern. It does not require the file names to be completely identical, only that the category code appears in the same position. For instance, the naming structure of the files in this example can be roughly understood as: three-digit number code + three-letter category code + five-digit serial number + extension.
This structure is very common in office files. Orders, equipment records, personnel files, logistics documents, report attachments, and data text files exported from systems often include a key field written into the file name. If this field's position is fixed, you can use the "categorize by characters within a custom position range" method for batch processing.
Typical scenarios suitable for this method include:
1. Batch archiving files by city or region, such as LON, NYC, PAR, SYD, TYO;
2. Batch organizing data by department code, for example, FIN for finance, HRD for HR, MKT for marketing;
3. Batch separating contracts, invoices, quotations, or delivery documents by client code;
4. Batch organizing Word documents (doc, docx) and PDF reports by project abbreviation;
5. Batch organizing Excel files (xls, xlsx) or txt data files by batch number;
6. Batch organizing attachments like images, audio, and video by a fixed identifier in the file name.
The common characteristics of these tasks are high repeatability, clear judgment rules, and low value in manual operation. Using office software for batch processing can free you from the process of mechanically moving files, allowing more time to be dedicated to content verification and business analysis.
Effect Preview: From a Chaotic File List to Clearly Categorized Folders
Before processing, all files are piled up in the same directory. As seen in the screenshot, the file list contains multiple txt files, each with a three-letter English code in its name. Red markers highlight the position of these codes, which are the basis for this categorization.

In this list, 128LON75957.txt and 200LON66460.txt both contain LON, indicating they should belong to the same category; 213TYO11946.txt and 307TYO91489.txt contain TYO and should go into the TYO folder; 230SYD60610.txt, 233SYD50778.txt, 254SYD54598.txt contain SYD and should go into the SYD folder. Manual categorization requires constantly observing these characters and moving files, whereas software can complete this automatically based on a unified rule.
After processing, the directory no longer contains a large number of scattered files but instead shows several folders named with the codes. The screenshot shows folders for LON, NYC, PAR, SYD, and TYO, indicating that the files have been categorized according to the three-letter codes extracted from their file names.

This sorting result offers two direct benefits: first, the folder names are the category codes, making them very intuitive to find; second, similar files are grouped together, making subsequent copying, packaging, sending, and archiving more convenient.
Operation Steps: Batch Archive by Characters 4 to 6 of the File Name
The following explains the operation based on the actual workflow in the software screenshots. HeSoft Doc Batch Tool is a batch tool designed for office file processing, with an interface providing entry points for File Organization, Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, Text Tools, etc. This time, we are using the file categorization by name capability within File Organization.
Step 1: Open the Categorize by File Name Function in File Organization
After launching the software, select "File Organization" in the left navigation bar. Function cards related to file organization will appear on the right, with the first function being "Categorize files by name". The red arrow in the screenshot points to this function, indicating it is the entry point for this task.

The reason for choosing this function is clear: our categorization basis comes from the file name, not the extension, creation time, or file content. The software will batch-allocate files to different folders according to character rules in the file names.
After completing this step, you will enter the wizard-style interface for "Categorize files by name". The top of the interface displays the processing workflow, including selecting records to process, setting processing options, setting save location, and starting processing. This workflow helps users complete batch processing step by step, reducing the possibility of missing key settings.
Step 2: Import the Files to be Organized and Check the List
Upon entering the function interface, you are first at Step 1, "Select records to process". The top right corner provides two main entry points: "Add Files" and "Import Files from Folder". If the target files are scattered, you can use "Add Files"; if the files are all in the same directory, using "Import Files from Folder" is more convenient.

After importing, the files appear in a table. The table in the screenshot lists information such as sequence number, name, path, extension, creation time, modification time, and actions. In the example, 20 records have been imported, all with a txt extension, and the file path is in the D:\test directory.
Do not rush to the next step at this point. It is recommended to perform three checks first: first, whether the number of records matches the number of files prepared for processing; second, whether all file names conform to the same naming rule; third, whether any files that should not be processed have been mixed in. If any anomalies are found, you can use the delete operation in the interface or "Clear" and then re-import.
After importing and verifying, click "Next" at the bottom to proceed to the processing options settings.
Step 3: Set the Categorization Method to Custom Position Range
In Step 2, "Set processing options", the software provides multiple rules for categorizing by file name. As seen in the screenshot, options include categorizing by the first character, by the first number, by the first English letter, by the first Chinese character, by the first English letter or Chinese character, by the first few characters, by the last few characters, by characters within a custom position range, and by a custom regular expression, etc.

In this example, the category code is in the middle of the file name, not the first character nor the last, so you should select "Categorize by characters within a custom position range". After selecting it, enter 4:6 in the "Range" input field.
The meaning of 4:6 is to start from the 4th character and end at the 6th character of the file name, extracting these three characters as the category folder name. Taking 128LON75957.txt as an example, the first three characters are 128, and the 4th to 6th characters are LON, so the categorization result is LON; for 943PAR93548.txt, the 4th to 6th characters are PAR, so the result is PAR.
This setting is the key to the entire operation. As long as the range is correctly selected, the software can batch-identify category codes according to the rule; if the range is incorrectly entered, for instance as 3:5 or 5:7, the extracted characters might not be the expected code, and the categorization result will deviate from the target. Therefore, before mass processing, it's recommended to manually count the character positions for a few typical files.
Step 4: Confirm the Letter Case Conversion Method
Below the categorization mode, you can see the "Letter Case Conversion" setting, with options including "Default", "Convert to uppercase", and "Convert to lowercase". The screenshot shows it kept as "Default".
If the codes in all file names are already uniformly uppercase, like LON, NYC, PAR, then keeping the default is fine. If files come from different systems and there might be a mix of lon, Lon, LON, you can consider uniformly converting them to uppercase or lowercase letters here, so that identical codes are grouped into the same folder.
In this example, the code format is consistent, so using the default setting is fine. This way, the processed folder names will retain the code style from the original file names.
Step 5: Continue to Set Save Location and Execute Processing
After completing the processing option settings, continue by clicking "Next". According to the interface flow, you will subsequently need to complete Step 3 "Set save location" and Step 4 "Start processing". Although the screenshot does not expand these two pages, the flow names clearly indicate: first determine where to save the categorization results, then start the batch processing.
It is recommended to choose an easily identifiable output location, such as creating a results folder next to the directory containing the original files, or using a dedicated archive directory. This clearly distinguishes pre-processing files from post-processing files, making verification easier.
After starting the processing, the software will automatically complete the categorization based on the 4th to 6th characters. Finally, opening the save location, you will see folders named by codes, such as LON, NYC, PAR, SYD, TYO. Files with corresponding codes are placed into each folder, completing the batch archiving.
Key Operation Points: How to Determine the Character Range in a File Name
When categorizing by position range, the most important step is to determine the start and end positions. A practical method is to take a representative file name and count character by character from left to right.
For example, with the file name 128LON75957.txt, if you only look at the main name 128LON75957: the 1st character is 1, the 2nd is 2, the 3rd is 8, the 4th is L, the 5th is O, and the 6th is N. That means LON is located from the 4th to the 6th position, hence you enter 4:6.
Take another example, 662PAR30266.txt, in its main name 662PAR30266, the 1st to 3rd characters are 662, and the 4th to 6th are PAR, so it will be sorted into the PAR folder. For 975TYO35070.txt, the 4th to 6th characters are TYO, so it will be sorted into the TYO folder.
If your files don't start with three digits but rather a two-digit code followed by a three-letter code, the range might be 3:5; if the file name starts with a date, like 20260622LON001.txt, the code position might be 9:11. Do not blindly copy 4:6; instead, determine the range based on your own file name structure.
Common Questions and Notes
1. Is it suitable to process a very large number of files all at once?
Batch processing tools are designed to reduce repetitive labor, but when the file count is especially high and the data is particularly important, it is recommended to first extract a small sample for testing. After confirming the categorization results are correct, proceed to process the entire directory.
2. Will inconsistent file name lengths affect the categorization?
If the category code is still within the same character range, it generally won't affect it; if the code's position varies for different files, extracting by a fixed range may not be applicable. In that case, you should first standardize the naming rules or choose another categorization method based on the actual situation.
3. Can it process Word, Excel, and PDF files?
The screenshot example in this article uses txt files, but the approach of categorizing by file name is not limited to txt. As long as the file names conform to the rules, this batch organization method can be referenced for doc, docx, xls, xlsx, ppt, pptx, pdf, and image files. Before actual processing, the final say should be based on what the software's import list shows.
4. Will inconsistent case create multiple folders?
If kept on the default setting, codes with different cases might be treated as different names. Therefore, when the file names contain mixed cases like LON, lon, Lon, it is recommended to choose a unified case in the "Letter Case Conversion" setting to avoid splitting similar files into separate folders.
5. Why set a save location?
Setting a save location keeps the processing results clearly separated from the original files, making verification and rollback easier. For batch archiving tasks, it is recommended not to repeatedly test within an important original directory; instead, use a test directory or backup files for verification.
Summary: Turning File Archiving from Manual Drag-and-Drop into Rule-Based Batch Processing
Categorizing files by a three-letter code in the middle of their name is essentially about handing over manual judgment rules to software for execution. As long as the file name structure is stable, such as when characters 4 to 6 represent a city, department, client, or project code, you can quickly complete archiving using HeSoft Doc Batch Tool .
The key workflow for this example is: enter File Organization, select "Categorize files by name"; import the files needing processing; in the processing options, choose "Categorize by characters within a custom position range"; set the range to 4:6; confirm the case method; continue to set the save location and start processing. After processing is complete, the files will be organized into categorized folders named with codes like LON, NYC, PAR, SYD, TYO.
If you frequently deal with a large volume of office files with similar naming conventions, it is recommended to incorporate this type of batch categorization method into your daily organization workflow. It not only saves time spent manually moving files but also reduces the risk of incorrect or missed sorting, making file management clearer, more standardized, and more efficient.