AI batch organize files
AI batch organize files
After using a computer for a long time, the Downloads folder always turns into a magical place.
It's piled up with various PDFs, Word documents, Excel files, images, and compressed packages, and the file names are all over the place:
最终版.docx,最终版2.docx,最终版-真的最终版.docx,微信图片_20261108.png……
When downloading files, it's hard to find them; if you look back a month later, you basically have to rely on luck.
If there are only a dozen or so files, manually creating a few folders will solve it. But if there are hundreds or even thousands of files, classifying, renaming, and moving them becomes very troublesome.
Now you can delegate these repetitive tasks to AI:Automatically recognize file types and content, design classification directories, batch rename, and organize files according to confirmed rules.
This chapter uses a practical case study to organize a folder containing reports, invoices, images, and Word documents using an AI Agent with file operation capabilities, such as Codex, WorkBuddy, or DuMate.
It should be noted that file organization involves actual read and write operations. Therefore, we will not have the AI move all the files right away, but rather adopta workflow of planning, previewing, confirming, and then executing and accepting.How it works.
I. What file organization tasks can AI help us complete
Traditional file management mainly relies on file names, extensions, and manual directory creation.
AI can combine file names, extensions, and the content of the files it can read to help us complete more flexible classification and organization.
| Application Scenarios | Tasks AI can complete |
|---|---|
| ** File Classification | Archiving according to types such as documents, images, receipts, and videos |
| ** Batch Renaming | Unify date, category, and sequence number in filenames |
| ** Content Recognition | Determine purpose based on readable content in PDF, Word, etc. |
| ** Duplicate File Detection | Discover files with identical content through file hash values |
| ** Archive by Date | Organize according to specified business date or file date |
| ** Operation Log | Save original path, new path, and organization results |
| ** File Recovery | Restore organized files based on backup and operation logs |
For example, we can tell the Agent:
Help me organize this test folder, put invoices in the receipt directory, reports and Word files in the document directory, and images in the image directory. Show me the organization plan first, and execute it after I confirm.
The Agent can first scan the directory and generate classification suggestions, and then execute file operations based on our confirmation.
However,AI cannot always accurately understand the purpose of each file.Files that cannot be classified should be placed in the "To Be Classified" list separately; do not guess arbitrarily.
II. Understand several important concepts in file organization first
Batch organization is different from ordinary text generation because the Agent may directly modify files on the computer.
Before starting the operation, clarify concepts such as the working directory, operation log, and file hash value.
1. What is the working directory
The working directory is the folder that the Agent is allowed to process this time.
For example, we create a directory namedtest-filesand only allow the AI to process the test files inside it, instead of authorizing access to the entire computer's Downloads directory.
This way, even if the classification rules have issues, the scope of impact is relatively easy to control.
2. What is the operation log
The operation log is used to record what changes occurred to each file.
For example:
| Original file | Target file | Operation |
|---|---|---|
| runoob-photo.png | images/runoob-photo.png | Copy |
| runoob-invoice.pdf | Voucher/runoob-invoice.pdf | Copy |
| runoob-report.pdf | Document/runoob-report.pdf | Copy |
If you find that a file is in the wrong location later, you can directly check the logs to know where it was originally.
3. What is SHA-256 file hash
SHA-256 is a common hashing algorithm that can calculate a fixed-length summary value based on file content.
For file organization, it has two very practical uses:
- To check if the file content is consistent before and after copying.
- To find duplicate files with identical content.
For example, two images with different filenames but the same SHA-256 value usually indicate that their file byte content is completely identical.
Conversely, if two images look the same but have different hash values after compression, cropping, or metadata modification.
4. What is the difference between copy, move, and delete?
| Operation | Result | Risk |
|---|---|---|
| ** Copy | Keeps the original file and generates a new copy | Relatively low, requires extra disk space |
| ** Move | Change file location | The original path no longer has the file |
| ** Rename | Change file name or path | May affect file references in other programs |
| ** Delete | Remove file | May cause irreversible data loss |
This lesson adopts a copy-first approach: first save the organized results to a new directory, and only consider moving the originals after verifying they are correct.
Furthermore, file overwriting, accidental deletion, and incorrect moving can all cause losses; one cannot assume that only overwrite operations pose a risk.
III. Practical Scenarios: Organizing a Messy Download Folder
Suppose we have a download directory containing reports, invoices, notes, and images.
These files are not categorized, and their names are not uniform, requiring organization into a clear directory structure.
To avoid affecting the actual data on the computer, we first use an independent test directory.
Prepare five test files
Create a directory namedtest-filesfolder, place the following five simulation files.
| File name | Content type | Suggested category |
|---|---|---|
| runoob-report.pdf | Project report | Document |
| runoob-notes.txt | Text Notes | Document |
| runoob-summary.docx | Word Summary | Document |
| runoob-photo.png | Image | Image |
| runoob-invoice.pdf | Simulated invoice | Voucher |
Special attention is needed here:runoob-report.pdfAndrunoob-invoice.pdfBoth are PDFs, but should be placed in different directories.
Therefore, this lesson cannot solely rely on file extension classification; it also requires judgment based on the filename and actual content.
If the file content does not match the filename, the actual file content should be checked first, and the filename should not be trusted directly.
Goal of this organization
We hope to organize these files into three categories:
- ** Documents: PDF reports, TXT notes, Word documents.
- ** Images: PNG, JPG, and other image files.
- ** Receipts: Vouchers such as invoices and receipts.
Files whose category cannot be confirmed will not be automatically archived and will be listed separately as "Pending Classification".
The complete process is as follows:
Four, Step One: Use Agent to check the file directory
These types of tasks require reading directories, judging file content, and creating organized results, so they are better suited for AI Agents with local file operation capabilities.
For example, you can use Codex, WorkBuddy, or DuMate and specify a local working directory if the tool supports it.
A regular chat model can formulate classification rules based on the file list we provide, but it does not mean it can directly access files on the computer.
First, let the AI scan, do not organize immediately.
After setting the test directory as the Agent's working directory, you can first input:
Example: Check folder contents
You are a file organization assistant.
Please check the test-files directory in the current project.
Currently, only file checking is performed.
Do not move, rename, or delete any files.
Please complete the following tasks:
List all regular files in the directory.
Count the total number of files.
Identify the extension and actual type of each file.
Read the content of files that can be safely parsed,
Determine the main purpose of the file.
Files with inconsistent names and content.
Find unrecognized files.
Check for suspected duplicate files.
Output a file list.
Field:
File name
|
File type
|
Content description
|
Suggested category
|
Basis for judgment
|
Whether confirmation is needed
Operation restrictions:
Only process the test-files directory.
Do not access files outside the directory.
Do not follow symbolic links pointing outside the directory.
Do not modify any file content.
Do not delete, move, or overwrite files.
Do not upload files to external services.
Wait for my confirmation on the next step after completion.
The key here is to let the Agent complete the file check first.
For example, forrunoob-invoice.pdf, it should confirm whether it belongs to a ticket based on the filename and the readable content.
If it cannot be determined, it should be marked as pending confirmation instead of being classified directly.
V. Second Step: Let the AI formulate a file classification plan
After confirming the file list, the next step is to let the AI design the directory structure.
For this exercise, only three classification folders are needed; there is no need to break down into more than a dozen subdirectories.
Expected directory structure
Organized directory structure
test-files/
├── runoob-report.pdf
├── runoob-notes.txt
├── runoob-summary.docx
├── runoob-photo.png
└── runoob-invoice.pdf
organized-files/
├── Documents/
│ ├── runoob-report.pdf
│ ├── runoob-notes.txt
│ └── runoob-summary.docx
│
├── Images/
│ └── runoob-photo.png
│
└── Invoices/
└── runoob-invoice.pdf
It can be seen that the originaltest-filesremains unchanged, and the organized results are saved separately toorganized-files.
This method reduces the risk of directly modifying the original file.
Let AI generate classification previews
Example: Generate file organization plan
File checking is complete.
Now please formulate a file organization plan.
Directory classification:
Documents
Images
Receipts
Unclassified
Classification rules:
Reports, summaries, and notes are categorized into documents.
Photos and regular images are categorized into pictures.
Vouchers such as invoices and receipts are categorized into receipts.
Files whose purpose cannot be determined are listed as pending classification.
Please judge based on the file name and actual content.
Output directory:
organized-files/
Please generate an organized preview table.
Field:
Original path
|
Suggested category
|
Target path
|
Basis for classification
|
Risk of name collision
|
Handling suggestions
Requirements:
Do not modify the original file.
Do not move any files.
Do not delete files.
Does not overwrite existing target files.
Retains the original extension.
Reports first in case of name conflicts.
Unrecognized files await confirmation.
Currently only outputs the organization plan.
Does not perform any file operations.
What should the organization preview look like
| Original file | Suggested categories | Target location |
|---|---|---|
| runoob-report.pdf | Documentation | Documentation/runoob-report.pdf |
| runoob-notes.txt | Documentation | Documentation/runoob-notes.txt |
| runoob-summary.docx | Document | Document/runoob-summary.docx |
| runoob-photo.png | Image | Image/runoob-photo.png |
| runoob-invoice.pdf | Receipt | runoob-invoice.pdf |
This is the expected classification result for this course's simulation file; it should still be confirmed based on the file content before actual execution.
VI. Step 3: Let AI Batch Rename Files
Besides classification, another common requirement in file organization is standardizing file names.
For example, one invoice is named123456.pdfand another is named微信文件_最终版.pdfEven if they are in the invoice directory, they are still hard to find later.
We can let AI generate more understandable names based on the file content and clear naming rules.
Common naming conventions
| File types | Suggested naming format |
|---|---|
| Work report | Date-Report Topic.pdf |
| Meeting minutes | Date-Meeting Topic.docx |
| Invoice | Date-Document Type-Number.pdf |
| Image | Date-Image Topic-Sequence.png |
| Project File | Project Name-File Purpose-Version Number.ext |
But note that:The date in the filename must be based on evidence.
If the file itself does not have a clear date, you can keep the original name or use the file system time after confirmation.
File creation time, modification time, and actual business date may not be the same and should not be confused.
Let AI design a renaming scheme
Example: Batch rename files
Please design a unified naming scheme for the current test files.
Currently, only a renaming preview is generated,
do not modify the files.
Naming rules:
File names should be concise and easy to understand.
Retain the original file extension.
Do not change the file content.
For files with a specific date,
the date can be used as a name prefix.
Do not invent a date for files without one.
The file's purpose should be based on its actual content.
Append a sequence number to files with the same name, for example -02.
Do not arbitrarily delete important information from the original filename.
Please output:
Original filename
|
Suggested new filename
|
Naming basis
|
Conflict existence
If there are files with insufficient information,
please keep the original name and mark it for confirmation.
Wait for my confirmation before proceeding.
For example, if it is a project report file, you can change it to a more specific project report name.runoob-report.pdfHowever, the original names of the five simulation files in this lesson are already quite clear, so you can keep them as they are during the actual practice and focus on learning the classification process.
VII. Step Four: Formal File Organization
Only after the file list, classification directory, and naming rules are all confirmed will you enter the actual execution phase.
Only after the file list, classification directory, and naming rules are all confirmed will the actual execution phase begin.
This lesson recommends copying the files first and keeping the original directory.
If you confirm that the organization results are correct, then decide whether to use it as a new official file directory.
Example: Execute the confirmed file organization plan
The file organization plan has been confirmed.
Now execute the confirmed classification plan.
Source directory:
test-files/
Output directory:
organized-files/
Execution requirements:
Only read regular files in test-files.
Organize according to the confirmed classification rules.
Copy the files to organized-files.
Keep all original files in the source directory.
Do not modify file content.
Do not overwrite any existing target files.
Do not perform delete operations.
Stop the file operation when a name conflict is encountered,
record the issue first, and do not overwrite arbitrarily.
When encountering an unidentifiable file,
pause the classification processing for that file.
Do not access or modify other directories.
Please generate a complete operation log.
The log must at least include:
Original path
Target path
File size
File SHA-256
Operation type
Execution result
Error reason (if any)
After execution:
Count the number of source files.
Count the number of successfully copied files.
Compare the SHA-256 of the source file and the copy.
List the failed or skipped files.
Do not automatically clean the source directory.
Provide a summary of the results and operation logs after completion.
After this step is complete, ideally there should be two directories:
test-files: to save the original test files.organized-filesSave a copy of the classified files.
This way, even if you are not satisfied with the classification results, you can directly modify the rules and regenerate the organized results without affecting the original data.
VIII. Step 5: Check if the files are complete
After the file organization is complete, you cannot just look at whether the directory is tidy.
You also need to confirm that every file has been processed correctly, that the content is not corrupted, and that no overwriting has occurred.
1. Count the number of files
In the Linux or macOS terminal, you can usefindto count the number of regular files.
Count the number of original files
find
test-files
-type
f
|
wc
-l
Number of files after statistical organization:
Number of files after statistical organization
find
organized-files
-type
f
|
wc
-l
This exercise has five files in total. If all copies are successful, both directories should have five regular files each.
However, the same number of files only indicates that the quantities are the same, not that the contents are identical.
2. Check file hashes
For example, in the macOS or Linux terminal, you can calculate SHA-256 using the tools provided by the system.
macOS can use:
Calculate SHA-256 on macOS
shasum
-a
256
test-files
/
runoob-report.pdf
shasum
-a
256
organized-files
/
Documentation
/
runoob-report.pdf
The hash values of the two files should be the same to confirm that the byte content of the file is consistent before and after copying.
For a large number of files, the Agent can automatically compare item by item based on the operation log instead of manual checking.
3. Generate acceptance report
Example: Check organization results
Please accept the results of this file organization.
Check scope:
Source directory:
test-files/
Target directory:
organized-files/
Operation log:
Use the logs generated by this organization.
Check the project:
Total number of original files.
Number of successfully copied files.
Whether there are any missing files.
Whether there are any unexpectedly added files.
Whether each file is in the correct category.
Whether the file sizes are consistent.
Whether SHA-256 matches.
Whether the target file was overwritten.
Whether there are unresolved conflicts.
Whether there are operations outside the access scope.
Please generate an acceptance report.
Mark each file as:
Passed / Failed / Pending confirmation
If there are issues,
Only report problems, do not delete or modify files arbitrarily.
After this step, the file organization will not only have clear directories but also explain how each file was processed.
Nine. Complete Example: A single prompt organizes the entire folder
Previously, the task was broken down into five stages: file inspection, classification planning, renaming, execution, and acceptance.
If you are already familiar with the operation, you can merge these requirements into one complete prompt to let the Agent complete it in stages.
Example: Complete prompt for AI batch file organization
You are a professional file management assistant.
Please help me organize a messy test folder.
Source directory:
test-files/
Output directory:
organized-files/
I. Task Goal
Organize files into a clear directory structure based on file name, type, and actual content.
Categorized directories:
Category directory:
Documentation
Image
Ticket
Unclassified
II. File Check
Please check first:
Total number of files
File name
File extension
Actual file type
File content purpose
File size
SHA-256
Suspected duplicate file
Unrecognized file
III. Classification rules
General reports and documents are categorized as "Documents".
Images are categorized as "Images".
Invoices and receipts are categorized as "Vouchers".
Files whose purpose cannot be confirmed are marked as "To Be Classified".
For PDFs,
Classification cannot be based solely on the extension.
Judgment should be made by combining the filename and the actual readable content.
Four. Renaming Rules
File names should be concise and readable.
Do not change the original extension.
Dates must be based on actual evidence.
Do not fabricate information in the file name.
Report name conflicts first.
Do not overwrite existing files.
V. Output the plan first
Please generate the summary preview table:
Original path
|
Target path
|
Classification basis
|
Suggested name
|
Risk
|
Requires confirmation
Before I confirm,
do not perform any file operations.
VI. Formal Execution
After confirming the plan:
Copy the files to organized-files.
Keep all files in test-files.
Do not modify the original file content.
Do not delete files.
Do not overwrite existing target files.
Do not access other directories.
Do not follow symbolic links pointing outside.
Skip and report upon conflict.
VII. Operation Log
Record:
Original path
New path
File size
File SHA-256
Operation type
Execution result
VIII. Acceptance verification
Check:
Whether the file count is correct.
Whether there are any omissions.
Whether the files are categorized correctly.
Whether the file contents are consistent.
Whether the SHA-256 matches.
Whether there has been any overwrite or deletion.
Whether there are any exceptions pending processing.
IX. Deliverables
Please provide:
The categorized file directory.
The file organization list.
Operation logs.
List of abnormal files.
Acceptance report.
All logs are saved to the project's independent log directory.
Do not mix in source files awaiting classification.
First, perform a file check and create a plan.
Wait for my confirmation before proceeding with the actual organization.
Expected organization results
Ultimately, a clearly classified directory, a file organization list, and an operation log should be obtained.
X. Advanced: Automatic organization of the download folder
After completing the test, you can try scenarios closer to daily use.
For example, the download directories of macOS and Windows often contain installation packages, PDFs, screenshots, compressed files, and various temporary materials.
We can let AI formulate a set of file download classification rules.
| File type | Suggested directory |
|---|---|
| PDF, DOCX, TXT | Documents |
| PNG, JPG, WEBP | Images |
| MP4, MOV | Video |
| ZIP, 7Z, RAR | Compressed archive |
| DMG, PKG, EXE, MSI | Installer package |
| Unrecognized file | To be classified |
This is only the first level of classification rules.
For example, a PDF could be an electronic invoice or a technical manual, and can be further subdivided based on its content after initial classification.
Automatic classification prompt
Example: Organize the Downloads folder
Please help me plan an organization scheme for my Downloads folder.
Do not operate on the actual Downloads directory directly.
First, based on the copy of the download directory I provide,
check the number and type of files.
Design the classification directories:
Documentation
Images
Videos
Compressed files
Installers
Vouchers
Uncategorized
Please complete:
File type statistics.
Classification rule design.
Duplicate name risk check.
Suggested directory structure.
File organization preview.
Do not move or delete files for now.
Submit the plan to me for confirmation first.
If executed later,
Prioritize copying to a new organized directory,
Keeping the original files.
It is recommended to test with a small number of files the first time, and not organize the entire download directory immediately.
Especially temporary files currently being downloaded, files being used by programs, and installer-related files should be avoided from being moved during use.
Eleven, Advanced: Organizing photos based on content
In addition to regular documents, AI can also help us organize photos.
For example, after a trip, there might be hundreds of pictures in the folder. We want to organize them by categories such as scenery, food, people, and architecture.
AI with visual understanding capabilities can provide classification suggestions based on the image content.
| Image Classification | Judgment Basis |
|---|---|
| ** Landscape | Natural scenery, mountains, oceans, etc. |
| ** Food | Dishes, beverages, dining table scenes |
| ** Architecture | Building exteriors, interior spaces |
| ** People | Images containing a main subject of a person |
| ** Unclassified | The main content cannot be accurately determined |
However, a photo may contain people, buildings, and scenery simultaneously, so classification rules should be determined in advance, such as classifying by the main subject, or allowing a photo to appear in multiple classification copies.
Example: AI Image Smart Classification
Please check the test image directory I provided.
Classify according to the image content.
Category type:
Scenery
Food
Architecture
People
Uncategorized
Requirements:
Prioritize classification based on the main content of the image.
Do not infer the real identity of the person in the photo.
Do not guess unconfirmed shooting locations.
Do not delete or modify the image.
Do not compress the original image.
Retain the original file name and format.
When an image may fit multiple categories,
Please state it first and wait for confirmation.
Please generate a classification preview first,
List the suggested category and basis for each image.
Do not move files for now.
For directories containing private photos, ensure that the tools and processing methods used comply with privacy requirements, and do not upload images to third-party services without permission.
XII. Advanced: Find duplicate files
This situation often occurs in downloaded folders:
report.pdf,report (1).pdf,report-copy.pdf.
It might be the same file, but you cannot delete it just because the names are similar.
You can first find exact duplicates using file hash values.
Difference between exact duplicates and similar files
| Type | Judgment method | Description |
|---|---|---|
| Exact duplicate | Compare file size and SHA-256 | Content byte consistency |
| Image similarity | Visual similarity or perceptual hash | May have been compressed or resized |
| Document similarity | Compare body content | May have different versions or minor modifications |
For completely duplicate files, a duplicate list can be generated; for similar documents, different versions should be retained and cannot be directly considered redundant files.
Example: Find duplicate files
Please check for duplicate files in the test directory.
First, use file size and SHA-256
to identify files with identical content.
Output:
Duplicate groups
|
File path
|
File size
|
SHA-256
|
Recommended files to keep
For files with similar content but different hashes,
Please list them separately as suspected similar files.
Requirements:
Do not automatically delete any files.
Do not determine duplication based on filename similarity alone.
Do not overwrite files.
Do not modify file content.
Files whose status cannot be confirmed are marked for verification.
Please output the duplicate file report first.
Do not execute deletion or moving without my confirmation.
Even if two files are confirmed to be identical, they may need to be kept simultaneously if they are referenced by different projects.
Therefore, duplicate detection and duplicate cleanup should be handled separately.
XIII. What to do if file organization goes wrong
If file classification errors, naming that does not meet expectations, or abnormal files appear in the target directory are found during the organization process, subsequent operations should be stopped first.
Do not continue executing the next batch of files while discovering problems.
First, let the Agent check the issues.
Example: Pause file organization and check
Please immediately pause the current file organization task.
Do not copy, move, rename, or delete files.
Please check:
How many files have been processed.
Which files have not been processed.
Which files are misclassified.
Whether there are duplicate name conflicts.
Whether any files have been overwritten.
Whether any operations are outside the authorized directory.
Whether there are files that failed to copy.
Please refer to the operation log,
and generate a problem report.
First list the suggested repair solutions.
Do not perform recovery or modification operations without my confirmation.
How to restore files before organization
If the copying method in this lesson is used, the original directory is still retained, so you can first check the original files and then regenerate the classification results.
If moving or renaming has already been performed, you need to restore based on the original path, target path, and operation log.
When restoring, also check if other files already exist in the original path; do not overwrite directly.
Example: Plan recovery based on operation logs.
Please use the operation logs from this file organization to
formulate a file recovery plan.
Currently, only a plan is formulated;
do not execute the recovery immediately.
Please list:
The original path before organization.
Current actual file path.
Suggested target path for restoration.
Whether there is a name conflict.
File size and SHA-256.
Which files cannot be safely restored.
Restoration requirements:
Do not overwrite existing files.
Do not delete other files.
Do not modify file content.
Do not process files other than logs.
Pause and report when a conflict is encountered.
First provide a recovery preview table,
and execute after I confirm.
Note that the operation log only records the operation process and is not equivalent to a file backup. If the original file has been overwritten or deleted, the content may not be recoverable solely from the log.
Therefore, for important data, it is best to keep an independent backup before starting the organization.
Fourteen, Frequently Asked Questions and Solutions
| Issue | Possible causes | Solutions |
|---|---|---|
| PDF invoices are categorized as general documents | Classification is based only on file extension | Check the content and purpose of the readable file |
| Conflict occurs with files of the same name | The target path already has a file with the same name | Stop the file operation and adopt the sequence number or keep the original name after confirmation |
| File was renamed incorrectly | Guess the name based on incomplete information | Keep the original name and manually confirm if necessary |
| File count mismatch | Copy failed, files missed, or extra files generated | Verify file mapping relationship item by item according to the logs |
| Classification result is inaccurate | File purpose is unclear | Mark as pending classification first, do not force archiving |
| Duplicate file detection is incorrect | Judgment is based only on filename or size | Use SHA-256 to determine exact duplicates |
| Some programs cannot find files after organization | Original file path has been moved or renamed | Restore original path and check program reference relationships |
| Agent operation scope is too large | Working directory or authorization permission settings are unreasonable | Stop the task and re-execute after limiting the directory scope |
| File content is corrupted | Copy or storage process is abnormal | Recover from a complete backup via hash check |
Fifteen, hands-on practice
Practice One: Organize ten different types of files
Create a test folder and place ten files such as PDF, Word, TXT, and images.
Let the AI first generate a classification preview, and after confirmation, copy them to directories such as documents, images, and receipts.
After completion, check the number of source and target files, and randomly check SHA-256.
Exercise Two: Batch Rename Photos
Prepare five test images and let the AI generate a renaming preview based on clear naming rules.
Require retaining the extension, not fabricating dates, and pausing when there is a name conflict.
Exercise Three: Find Duplicate Files
Copy the same PDF, create two files with different names, and then let the AI check for duplicates using SHA-256.
Only output the duplicate list, do not delete.
Exercise four: Restore the directory before organization
Perform a simple file move in the test directory and save the operation log.
Then have the AI formulate a recovery plan based on the log, execute the recovery after checking the target path, and confirm if the files have returned to their original location.