How to Automatically Organize Android Downloads Using Termux & Python (2026)

Termux Python automation on Android


Does your Android Downloads folder contain hundreds of PDFs, images, ZIP files, videos, documents, and other files?

Finding an important file in a cluttered Downloads folder can be frustrating. Instead of organizing everything manually, you can automate the process using Termux and Python.

In this tutorial, we will create a simple Python automation script that scans your Android Downloads folder and automatically moves files into separate folders such as:

  • 📷 Images
  • 📄 Documents
  • 📦 Archives
  • 🎵🎬 Media

This is a simple but useful Android automation project for anyone learning Python, Linux commands, or Termux.


What You Need

Before starting, you need:

  • An Android smartphone
  • Termux
  • Basic knowledge of Android file storage
  • Internet connection for installing packages
  • Python
> **Important:** Install Termux from a trusted source such as F-Droid or the official Termux project. Different Termux versions may have slightly different storage behavior.

What Is Termux?

Termux is an Android terminal emulator that provides a Linux-like command-line environment on your smartphone.

It allows you to install programming languages and utilities such as:

  • Python
  • Git
  • Node.js
  • PHP
  • SSH
  • Nano
  • Linux command-line tools

For this project, we will use Python to automate file organization.


Step 1: Install Termux

Install Termux on your Android phone from a trusted source.

After installation, open the application.

You should see a terminal window similar to a Linux command prompt.


Step 2: Give Termux Storage Permission

Termux needs permission to access your shared Android storage.

Termux storage permission setup on Android


Run:

termux-setup-storage

Android will display a permission request.

Tap Allow.

After successful setup, Termux normally creates a storage shortcut at:

~/storage/shared

This points to your phone's shared internal storage.


Step 3: Update Termux Packages

Before installing Python, update the package list.

Run:

pkg update

If you want to upgrade installed packages as well:

pkg update && pkg upgrade

If Termux asks for confirmation, type:

y

and press Enter.


Step 4: Install Python

Install Python using:

pkg install python

Check whether Python was installed correctly:

python --version

You should see the installed Python version.

Installing Python in Termux



Step 5: Locate the Downloads Folder

After running termux-setup-storage, use:

cd ~/storage/shared/Download

Check the contents of the folder:

ls

You should see the files currently stored in your Downloads folder.

If your phone uses a different Downloads location

You can check the shared storage directory using:

ls ~/storage/shared

Look for a folder named:

Download

or another appropriate Downloads directory.


Step 6: Create the Python Automation Script

Now create a Python file:

nano organizer.py

The Nano editor will open.

Paste the following code:

import os
import shutil

downloads_path = os.path.expanduser("~/storage/shared/Download")

file_types = {
    "Images": [".jpg", ".jpeg", ".png", ".gif", ".webp"],
    "Documents": [".pdf", ".doc", ".docx", ".txt", ".xlsx", ".xls"],
    "Archives": [".zip", ".rar", ".7z", ".tar", ".gz"],
    "Media": [".mp4", ".mkv", ".avi", ".mp3", ".wav", ".flac"],
}

if not os.path.exists(downloads_path):
    print("Downloads folder was not found.")
    exit()

for filename in os.listdir(downloads_path):

    filepath = os.path.join(downloads_path, filename)

    if os.path.isfile(filepath):

        ext = os.path.splitext(filename)[1].lower()

        for folder_name, extensions in file_types.items():

            if ext in extensions:

                folder_path = os.path.join(
                    downloads_path,
                    folder_name
                )

                os.makedirs(folder_path, exist_ok=True)

                destination = os.path.join(
                    folder_path,
                    filename
                )

                # Avoid overwriting an existing file
                if os.path.exists(destination):
                    print(f"Skipped: {filename} (already exists)")
                else:
                    shutil.move(filepath, destination)
                    print(
                        f"Moved: {filename} → {folder_name}/"
                    )

                break

print("File organization completed!")

Creating organizer.py using Nano in Termux


Step 7: Save the Python File

If you are using Nano:

Press:

CTRL + O

Press Enter to save.

Then press:

CTRL + X

to exit Nano.

Your Python script is now saved as:

organizer.py

Step 8: Run the Automation

Run:

python organizer.py

The script will scan your Downloads folder.

For example, if your Downloads folder contains:

photo.jpg
invoice.pdf
movie.mp4
backup.zip
song.mp3

the script will create folders and move the files like this:

Download/
│
├── Images/
│   └── photo.jpg
│
├── Documents/
│   └── invoice.pdf
│
├── Media/
│   ├── movie.mp4
│   └── song.mp3
│
└── Archives/
    └── backup.zip

Python script organizing Android files


Step 9: Check the Result

Run:

ls

You should now see folders such as:

Images
Documents
Archives
Media

You can also open your Android file manager and check the Downloads folder.

Before and after Android Downloads organization



How Does the Python Script Work?

The script uses Python's built-in libraries.

os

The os module allows Python to work with files and directories.

For example:

os.listdir(downloads_path)

gets the files inside the Downloads folder.


shutil

The shutil module is used to move files.

The important command is:

shutil.move(filepath, destination)

It moves a file from one location to another.


File Extension Detection

The script checks the extension of every file:

ext = os.path.splitext(filename)[1].lower()

For example:

photo.JPG → .jpg
document.PDF → .pdf
video.MP4 → .mp4

Converting the extension to lowercase makes the script work with both uppercase and lowercase extensions.


Can You Add More File Types?

Yes.

For example, you can add APK files:

"Apps": [".apk"],

You can also add programming files:

"Code": [".py", ".js", ".html", ".css"],

And compressed files:

"Archives": [".zip", ".rar", ".7z", ".tar", ".gz"],

You can customize the categories according to your requirements.


Important Safety Tips

Before using any automatic file-moving script, remember:

1. Test It With Unimportant Files

First create a few test files and make sure the script behaves as expected.

2. Don't Organize Important System Folders

Use the script only with a folder where moving files is safe.

3. Keep Backups

Do not rely on an automation script as your only backup system.

4. Check Duplicate Files

This version checks whether a file with the same name already exists before moving it.


Can This Run Automatically?

Yes, but running Python manually every time isn't true automation.

You can take this project further by using Android automation tools or scheduled Termux commands.

For example, you could eventually create a workflow where the organizer runs periodically instead of manually executing:

python organizer.py

This makes the project much more powerful.


Useful Termux Commands

Here are some useful commands for beginners:

Check current directory

pwd

List files

ls

Change directory

cd folder-name

Go back

cd ..

Create a folder

mkdir Test

Create a Python file

nano script.py

Run Python

python script.py

Check Python version

python --version

Why This Is a Good Python Project

This small project demonstrates several useful programming concepts:

  • Python file handling
  • Directory management
  • Conditional statements
  • Loops
  • Lists and dictionaries
  • String processing
  • Automation
  • Linux/Termux commands

It can also be expanded into a much more advanced Android automation project.


Ideas for Version 2

Once the basic version works, you can add features such as:

  • Automatic date-based folders
  • Separate APK folder
  • Separate ZIP/RAR folder
  • Screenshot detection
  • WhatsApp media organization
  • Duplicate-file detection
  • File-size filtering
  • Automatic logging
  • Scheduled execution
  • Custom folder rules
  • Command-line options
  • Notification after completion

For example, you could eventually create a command such as:

python organizer.py

that reports:

Files scanned: 35
Images moved: 12
Documents moved: 8
Media moved: 10
Archives moved: 5

Organization completed successfully!

Conclusion

With Termux + Python, you can turn your Android phone into a small automation environment.

The Downloads Organizer project is a simple example of how Python can interact with files and directories on Android.

Instead of manually moving hundreds of files, you can let a Python script handle the repetitive work.

If you're learning Python, this is also a practical project because you're not just writing code—you are using Python to solve a real problem on your smartphone.

More Termux, Python, Android automation and technology tutorials are coming on Roysfan.in.



 Frequently Asked Questions:-


Can Termux organize Android files automatically?

Yes. With storage permission and a Python script, Termux can automate many file-management tasks in shared Android storage.

Can I use Python on Android?

Yes. Termux allows you to install and run Python directly on compatible Android devices.

Is this Termux file organizer safe?

The script should be tested with non-important files first. Always keep backups of important data before using automated file-moving scripts.

Can I add more file types?

Yes. You can modify the Python dictionary to add extensions such as APK, CSV, PPTX, JSON, HTML and other file types.

Can this script run automatically?

Yes. The project can be extended with scheduled or Android automation methods so that the script runs periodically instead of manually.



Suggested Internal Links


  • Termux Commands for Android
  • Python Projects for Beginners
  • Android Bootable USB Guide
  • Best Android Automation Tools
How to Automatically Organize Android Downloads Using Termux & Python (2026) How to Automatically Organize Android Downloads Using Termux & Python (2026) Reviewed by Surjeet Roy on October 07, 2026 Rating: 5

No comments:

To insert a short code, use & lt; i rel = & quot; code & quot; & gt; ... CODE ... & lt; / i & gt;
To insert a long code, use & lt; i rel = & quot; pre & quot; & gt; ... CODE ... & lt; / i & gt;
To insert an image, use & lt; i rel = & quot; image & quot; & gt; ... PICTURE URL ... & lt; / i & gt;

Powered by Blogger.