Batch file rename (based on file content, possibly AI related)


jro11

Well-known member
Member
Local time
12:46 AM
Posts
604
OS
Win11 Home
I have a slew of files CoPilot-generated files relating to questions I posed this AI engine. They are all named:
CopilotAnswers-unique number,docx​
I brought up one of these files in Word and asked Copilot if it could rename the file based on its content. It replied it could do so (even provided example names...not bad, not bad at all). However, I want to do this as a batch process and CoPilot can't open or rename files. I understand there are Python routines and downloadable apps that can do this, as a Batch process.
I'm hoping the file can be renamed based on the content of the file, not just some numbering/date/... scheme independent of the file's content--a process AI seems particularly adept at.
Have you had any experience doing this? What has your experience been? What recommendations do you have?
Thanks
 

My Computers

System One System Two

  • OS
    Win11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inc. Inspiron 16 7610
    CPU
    Dell Inc. 0FHWFD A01
    Motherboard
    Dell Inc. 0FHWFD A01
    Memory
    16GB
    Graphics Card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    laptop (small) and 1 or 2 external monitors
    Screen Resolution
    -
    Hard Drives
    PC711 NVMe SK hynix 1TB 1.02 TB NVMe ANB2N582412102F0G_0001
    PSU
    -
    Case
    Laptop
    Cooling
    fan
    Keyboard
    External!
    Mouse
    External
    Internet Speed
    -
    Browser
    Chrome (Chrome profiles), Firefox (Bookmark Search Plus2), Edge (History page), Opera (annoying)
    Antivirus
    WinDefender
    Other Info
    Win11 Home 23H2 22631.3447
  • Operating System
    Win10
    Computer type
    PC/Desktop
    Manufacturer/Model
    self
    Motherboard
    Gigabyte B75M-D3H
    Memory
    8068 MB Usable Installed Memory
    Graphics card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    3 Displays
    Screen Resolution
    n/a
    Hard Drives
    SSD and others (internal and external)
    Case
    Desktop
    Cooling
    Fan
    Mouse
    External
    Keyboard
    External
    Browser
    Chrome, Firefox, Tor, Brave, Opera, etc.
    Antivirus
    Win Defender
    Other Info
    Win10 & unfortunately OneDrive: Can't completely rid myself of this!!
Do you have some examples of what kind of content you want to identify? If you are going to do this via program, then you need to be able to tell the program something precise to look for in the contents of the file otherwise how will it know what criteria you want to use to perform a certain type of rename?

Of course, if you are talking about something as broad as determining if it is a Word doc, or a spreadsheet, etc. then you could simply look at the file extension. But beyond that, you would simply have to parse the contents of the file and look for something that will tell it what that file is.
 

My Computers

System One System Two

  • OS
    Win11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self-built
    CPU
    Intel i7 11700K
    Motherboard
    ASUS Prime Z590-A MB
    Memory
    64GB (Waiting for warranty replacement of another 64GB for 128GB total)
    Graphics Card(s)
    No GPU - Built-in Intel Graphics
    Sound Card
    Integrated
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe SSD
    1 x 2TB NVMe SSD
    1 x 4TB NVMe SSD
    3 x 512GB 2.5" SSD
    1 x 4TB 2.5" SSD
    5 x 8TB Seagate Barracuda HDD
    PSU
    Corsair HX850i
    Case
    Corsair iCUE RGB 5000X mid tower case
    Cooling
    Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Home Computer Specifications, Configuration, and Usage Notes General Specifications ASUS Prime Z590-A motherboard, serial number M1M0KC222467ARP Intel Core i7-11700K CPU (11th Gen Rocket Lake / LGA 1200 Socket) 128GB Crucial Ballistix RGB DDR4 3200 MHz DRAM (4 x 32GB) Corsair iCUE RGB 5000X mid tower case Noctua NH-D15 chromax.black CPU cooler Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Corsair LL-120 RGB Fans (Qty. 3)
    Keyboard
    Corsair K70 Max RGB Magnetic Keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    The five 8TB drives and three 512GB SSDs are part of a DrivePool using StableBit DrivePool software. The three SSDs are devoted purely to caching for the 8TB drives. All of the important data is stored in triplicate so that I can withstand simultaneous failure of 2 disks.

    Networking: 2.5Gbps Ethernet and WiFi 6e
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor
If you are going to do this via program, then you need to be able to tell the program something precise to look for in the contents of the file otherwise how will it know what criteria you want to use to perform a certain type of rename?
AI generated over 90% of each file; when I asked ChatGPT, it looked at the document from which I addressed it (you can open CoPilot within Word) and provided me with a number of possible alternative names; If I bring up CoPilot I see a list of names it's already given to our 'conversations'--so in essence it's already done the hard work.

Figuring out a name is the least I can expect of AI. Where it seems to have a problem is in a) opening a document, and, b) renaming it.
(Instead Copilot (aka Microsoft) picked the most inane way of naming these documents...
But beyond that, you would simply have to parse the contents of the file and look for something that will tell it what that file is.
For 200+ documents?
 

My Computers

System One System Two

  • OS
    Win11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inc. Inspiron 16 7610
    CPU
    Dell Inc. 0FHWFD A01
    Motherboard
    Dell Inc. 0FHWFD A01
    Memory
    16GB
    Graphics Card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    laptop (small) and 1 or 2 external monitors
    Screen Resolution
    -
    Hard Drives
    PC711 NVMe SK hynix 1TB 1.02 TB NVMe ANB2N582412102F0G_0001
    PSU
    -
    Case
    Laptop
    Cooling
    fan
    Keyboard
    External!
    Mouse
    External
    Internet Speed
    -
    Browser
    Chrome (Chrome profiles), Firefox (Bookmark Search Plus2), Edge (History page), Opera (annoying)
    Antivirus
    WinDefender
    Other Info
    Win11 Home 23H2 22631.3447
  • Operating System
    Win10
    Computer type
    PC/Desktop
    Manufacturer/Model
    self
    Motherboard
    Gigabyte B75M-D3H
    Memory
    8068 MB Usable Installed Memory
    Graphics card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    3 Displays
    Screen Resolution
    n/a
    Hard Drives
    SSD and others (internal and external)
    Case
    Desktop
    Cooling
    Fan
    Mouse
    External
    Keyboard
    External
    Browser
    Chrome, Firefox, Tor, Brave, Opera, etc.
    Antivirus
    Win Defender
    Other Info
    Win10 & unfortunately OneDrive: Can't completely rid myself of this!!
AI generated over 90% of each file; when I asked ChatGPT, it looked at the document from which I addressed it (you can open CoPilot within Word) and provided me with a number of possible alternative names; If I bring up CoPilot I see a list of names it's already given to our 'conversations'--so in essence it's already done the hard work.

Figuring out a name is the least I can expect of AI. Where it seems to have a problem is in a) opening a document, and, b) renaming it.
(Instead Copilot (aka Microsoft) picked the most inane way of naming these documents...

For 200+ documents?

Sure, a program could parse thousands or tens of thousands of files rapidly.
 

My Computers

System One System Two

  • OS
    Win11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self-built
    CPU
    Intel i7 11700K
    Motherboard
    ASUS Prime Z590-A MB
    Memory
    64GB (Waiting for warranty replacement of another 64GB for 128GB total)
    Graphics Card(s)
    No GPU - Built-in Intel Graphics
    Sound Card
    Integrated
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe SSD
    1 x 2TB NVMe SSD
    1 x 4TB NVMe SSD
    3 x 512GB 2.5" SSD
    1 x 4TB 2.5" SSD
    5 x 8TB Seagate Barracuda HDD
    PSU
    Corsair HX850i
    Case
    Corsair iCUE RGB 5000X mid tower case
    Cooling
    Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Home Computer Specifications, Configuration, and Usage Notes General Specifications ASUS Prime Z590-A motherboard, serial number M1M0KC222467ARP Intel Core i7-11700K CPU (11th Gen Rocket Lake / LGA 1200 Socket) 128GB Crucial Ballistix RGB DDR4 3200 MHz DRAM (4 x 32GB) Corsair iCUE RGB 5000X mid tower case Noctua NH-D15 chromax.black CPU cooler Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Corsair LL-120 RGB Fans (Qty. 3)
    Keyboard
    Corsair K70 Max RGB Magnetic Keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    The five 8TB drives and three 512GB SSDs are part of a DrivePool using StableBit DrivePool software. The three SSDs are devoted purely to caching for the 8TB drives. All of the important data is stored in triplicate so that I can withstand simultaneous failure of 2 disks.

    Networking: 2.5Gbps Ethernet and WiFi 6e
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor
I've bulk-renamed files using one of the third-party file managers such as Free Commander, Multi Commander, Total Commander, etc. [many are free] to change file names, mostly to remove extraneous characters with nothing, only take out what is designated. The key was all the files had the same characters where the rest of the file name was different. I put the paid version of Total Commander on my computers plus on USB Thumb drives with other diagnostics. An example is in a list of songs for a single performer whose name was on all the files, removed instances of that name leaving the song title intact [replaced the name with nothing]. I've also use the program to bulk change the Attributes of files such as date of creation.
 

My Computers

System One System Two

  • OS
    Win11 Pro RTM
    Computer type
    Laptop
    Manufacturer/Model
    Dell Vostro 3400
    CPU
    Intel Core i5 11th Gen. 2.40GHz
    Memory
    12GB
    Hard Drives
    256GB SSD NVMe M.2
  • Operating System
    Windows 11 Pro RTM x64
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Vostro 5890
    CPU
    Intel Core i5 10th Gen. 2.90GHz
    Memory
    16GB
    Graphics card(s)
    Onboard, no VGA, using a DisplayPort-to-VGA adapter
    Monitor(s) Displays
    24" Dell
    Hard Drives
    512GB SSD NVMe, 4TB Seagate HDD
    Browser
    Firefox, Edge
    Antivirus
    Windows Defender/Microsoft Security

My Computers

System One System Two

  • OS
    Win11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inc. Inspiron 16 7610
    CPU
    Dell Inc. 0FHWFD A01
    Motherboard
    Dell Inc. 0FHWFD A01
    Memory
    16GB
    Graphics Card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    laptop (small) and 1 or 2 external monitors
    Screen Resolution
    -
    Hard Drives
    PC711 NVMe SK hynix 1TB 1.02 TB NVMe ANB2N582412102F0G_0001
    PSU
    -
    Case
    Laptop
    Cooling
    fan
    Keyboard
    External!
    Mouse
    External
    Internet Speed
    -
    Browser
    Chrome (Chrome profiles), Firefox (Bookmark Search Plus2), Edge (History page), Opera (annoying)
    Antivirus
    WinDefender
    Other Info
    Win11 Home 23H2 22631.3447
  • Operating System
    Win10
    Computer type
    PC/Desktop
    Manufacturer/Model
    self
    Motherboard
    Gigabyte B75M-D3H
    Memory
    8068 MB Usable Installed Memory
    Graphics card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    3 Displays
    Screen Resolution
    n/a
    Hard Drives
    SSD and others (internal and external)
    Case
    Desktop
    Cooling
    Fan
    Mouse
    External
    Keyboard
    External
    Browser
    Chrome, Firefox, Tor, Brave, Opera, etc.
    Antivirus
    Win Defender
    Other Info
    Win10 & unfortunately OneDrive: Can't completely rid myself of this!!
And the name of that program is???
It is whatever you name it after you write it :-). Seriously, it would be super easy to write in a few minutes once you know what you are specifically looking for.
 

My Computers

System One System Two

  • OS
    Win11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Self-built
    CPU
    Intel i7 11700K
    Motherboard
    ASUS Prime Z590-A MB
    Memory
    64GB (Waiting for warranty replacement of another 64GB for 128GB total)
    Graphics Card(s)
    No GPU - Built-in Intel Graphics
    Sound Card
    Integrated
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe SSD
    1 x 2TB NVMe SSD
    1 x 4TB NVMe SSD
    3 x 512GB 2.5" SSD
    1 x 4TB 2.5" SSD
    5 x 8TB Seagate Barracuda HDD
    PSU
    Corsair HX850i
    Case
    Corsair iCUE RGB 5000X mid tower case
    Cooling
    Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Home Computer Specifications, Configuration, and Usage Notes General Specifications ASUS Prime Z590-A motherboard, serial number M1M0KC222467ARP Intel Core i7-11700K CPU (11th Gen Rocket Lake / LGA 1200 Socket) 128GB Crucial Ballistix RGB DDR4 3200 MHz DRAM (4 x 32GB) Corsair iCUE RGB 5000X mid tower case Noctua NH-D15 chromax.black CPU cooler Noctua NF-S12A chromax.black.swap case fans (Qty. 7) & Corsair LL-120 RGB Fans (Qty. 3)
    Keyboard
    Corsair K70 Max RGB Magnetic Keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    The five 8TB drives and three 512GB SSDs are part of a DrivePool using StableBit DrivePool software. The three SSDs are devoted purely to caching for the 8TB drives. All of the important data is stored in triplicate so that I can withstand simultaneous failure of 2 disks.

    Networking: 2.5Gbps Ethernet and WiFi 6e
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor
Seriously, it would be super easy to write in a few minutes once you know what you are specifically looking for.
Seriously,

Batch file rename (based on file content, possibly AI related)​

I have a slew of files CoPilot-generated files relating to questions I posed this AI engine. They are all named:
[]CopilotAnswers-unique number,docx[/]I brought up one of these files in Word and asked Copilot if it could rename the file based on its content. It replied it could do so (even provided example names...not bad, not bad at all). However, I want to do this as a batch process and CoPilot can't open or rename files. I understand there are Python routines and downloadable apps that can do this, as a Batch process.
I'm hoping the file can be renamed based on the content of the file, not just some numbering/date/... scheme independent of the file's content--a process AI seems particularly adept at.
Have you had any experience doing this? What has your experience been? What recommendations do you have?

 

My Computers

System One System Two

  • OS
    Win11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inc. Inspiron 16 7610
    CPU
    Dell Inc. 0FHWFD A01
    Motherboard
    Dell Inc. 0FHWFD A01
    Memory
    16GB
    Graphics Card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    laptop (small) and 1 or 2 external monitors
    Screen Resolution
    -
    Hard Drives
    PC711 NVMe SK hynix 1TB 1.02 TB NVMe ANB2N582412102F0G_0001
    PSU
    -
    Case
    Laptop
    Cooling
    fan
    Keyboard
    External!
    Mouse
    External
    Internet Speed
    -
    Browser
    Chrome (Chrome profiles), Firefox (Bookmark Search Plus2), Edge (History page), Opera (annoying)
    Antivirus
    WinDefender
    Other Info
    Win11 Home 23H2 22631.3447
  • Operating System
    Win10
    Computer type
    PC/Desktop
    Manufacturer/Model
    self
    Motherboard
    Gigabyte B75M-D3H
    Memory
    8068 MB Usable Installed Memory
    Graphics card(s)
    2.30 gigahertz Intel 11th Gen Core i7-11800H
    Sound Card
    Intel® Smart Sound Technology for USB Audio
    Monitor(s) Displays
    3 Displays
    Screen Resolution
    n/a
    Hard Drives
    SSD and others (internal and external)
    Case
    Desktop
    Cooling
    Fan
    Mouse
    External
    Keyboard
    External
    Browser
    Chrome, Firefox, Tor, Brave, Opera, etc.
    Antivirus
    Win Defender
    Other Info
    Win10 & unfortunately OneDrive: Can't completely rid myself of this!!
Seriously,

Batch file rename (based on file content, possibly AI related)​


Seriously…

Taking a guess here:

You copied the text from one of the document files into Co-Pilot (or uploaded it?) You’re basing your request on the fact AI can read the document so surmise a title. If you can upload multiple documents, maybe this could be possible.

Do you have an AI app on your PC that can surmise files? I’d guess not.

If the docx files have an entry in the “Subject” properties metadata (Apparently there is such a field that I don’t know anything about) then you could possibly do it with a Powershell Script


PowerShell script to rename all `.docx` files in a specified folder based on the "Subject" property of each file's metadata:

Powershell:
# Specify the folder containing the .docx files
$folderPath = "C:\Path\To\Your\Folder"

# Check if the folder exists
if (!(Test-Path $folderPath)) {
    Write-Host "Folder not found: $folderPath"
    exit
}

# Get all .docx files in the folder
$docxFiles = Get-ChildItem -Path $folderPath -Filter *.docx

# Loop through each .docx file
foreach ($file in $docxFiles) {
    try {
        # Open the document as a ComObject
        $word = New-Object -ComObject Word.Application
        $doc = $word.Documents.Open($file.FullName)

        # Extract the Subject property
        $subject = $doc.BuiltInDocumentProperties.Item("Subject").Value

        # Close the document and quit Word
        $doc.Close()
        $word.Quit()

        # Check if the Subject is not empty or null
        if (![string]::IsNullOrWhiteSpace($subject)) {
            # Define the new file name using the Subject property
            $newFileName = "$subject.docx"

            # Rename the file
            Rename-Item -Path $file.FullName -NewName $newFileName -ErrorAction Stop
            Write-Host "Renamed '$($file.Name)' to '$newFileName'"
        } else {
            Write-Host "Subject property is empty for '$($file.Name)'"
        }
    } catch {
        Write-Host "Error processing '$($file.Name)': $_"
    }
}

  • Modify the `$folderPath` variable to the path where your `.docx` files are located.
  • Copy and paste the script** into a `.ps1` file (e.g., `RenameDocxFiles.ps1`). Save it in the folder where the documents are.
  • Run the script in PowerShell:
    • Open PowerShell as Administrator.
    • Navigate to the folder where the `.ps1` file is saved.
    • Execute the script by typing: `.\RenameDocxFiles.ps1`.

  • The script uses the Microsoft Word COM object to extract the metadata (`Subject`) from each `.docx` file. As long as you have Word installed on your system. (You do)
  • If a file’s "Subject" property is empty, the script will skip renaming that file.

If you’re going to try, I’d make backups.



As the likelihood of you having an AI program installed on your system is ZERO, Python is apparently an option.


Renaming `.docx` files based on the subject matter they contain requires analyzing the content of each file to determine its primary focus. You could apparently use a Python script to utilise the `python-docx` library to extract text and rename files based on a simple keyword analysis. This script also integrates Copilot-like reasoning to infer the document's subject.

You would first need to have Python setup/installed:

Code:
import os
import re
from collections import Counter
from docx import Document

def infer_subject(text):
    """
    Analyze text content to determine the main subject.
    """
    # Basic word frequency analysis
    words = re.findall(r'\b\w+\b', text.lower())
    common_words = ["the", "and", "to", "of", "in", "a", "is", "for", "on", "that", "with", "as", "by", "at", "an"]
    keywords = [word for word in words if word not in common_words]
    most_common = Counter(keywords).most_common(3)  # Top 3 keywords
    return "_".join([item[0] for item in most_common])  # Combine keywords as the "subject"

def rename_files_in_folder(folder_path):
    """
    Rename all .docx files in a folder based on their inferred subject.
    """
    if not os.path.exists(folder_path):
        print(f"Folder not found: {folder_path}")
        return

    for file_name in os.listdir(folder_path):
        if file_name.endswith(".docx"):
            file_path = os.path.join(folder_path, file_name)
            try:
                # Extract text from the .docx file
                doc = Document(file_path)
                text = " ".join([para.text for para in doc.paragraphs])

                # Infer the subject of the document
                subject = infer_subject(text)
                if subject:
                    # Generate new file name based on the subject
                    new_file_name = f"{subject}.docx"
                    new_file_path = os.path.join(folder_path, new_file_name)

                    # Rename the file
                    os.rename(file_path, new_file_path)
                    print(f"Renamed '{file_name}' to '{new_file_name}'")
                else:
                    print(f"Could not infer subject for '{file_name}'")
            except Exception as e:
                print(f"Error processing '{file_name}': {e}")

# Specify the folder containing the .docx files
folder_path = r"C:\Path\To\Your\Folder"
rename_files_in_folder(folder_path)


  • Reads `.docx` Content: Extracts text from each `.docx` file in the folder.
  • Analyzes Text: Uses basic keyword frequency analysis to infer the subject matter (removing common filler words).
  • Renames Files: Generates a new name based on the top 3 keywords (e.g., `project_plan_review.docx`).

  1. File `Document1.docx` contains the text: *"This document discusses project plans and reviews regarding marketing."*
  2. The script renames the file to `project_plans_reviews.docx`.

Notes: Apparently

You can enhance the script by using more advanced Natural Language Processing (NLP) techniques (e.g., libraries like `spaCy` or `transformers`).


At the emd of the day, I can’t see how you couldn’t of been aware that you were saving files without a descriptive title. Learn how to give a document a filename “before” you click the save or save as button
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 Build 22631.5039
    Computer type
    PC/Desktop
    Manufacturer/Model
    Sin-built
    CPU
    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz (4th Gen?)
    Motherboard
    ASUS ROG Maximus VI Formula
    Memory
    32.0 GB of I forget and the box is in storage.
    Graphics Card(s)
    Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    Sound Card
    Onboard
    Monitor(s) Displays
    5 x LG 25MS500-B - 1 x 24MK430H-B - 1 x Wacom Pro 22" Tablet
    Screen Resolution
    All over the place
    Hard Drives
    Too many to list.
    OS on Samsung 1TB 870 QVO SATA
    PSU
    Silverstone 1500
    Case
    NZXT Phantom 820 Full-Tower Case
    Cooling
    Noctua NH-D15 Elite Class Dual Tower CPU Cooler / 6 x EziDIY 120mm / 2 x Corsair 140mm somethings / 1 x 140mm Thermaltake something / 2 x 200mm Corsair.
    Keyboard
    Corsair K95 / Logitech diNovo Edge Wireless
    Mouse
    Logitech: G402 / G502 / Mx Masters / MX Air Cordless
    Internet Speed
    1000/400Mbps
    Browser
    All sorts
    Antivirus
    Kaspersky Premium
    Other Info
    I’m on a horse.
  • Operating System
    Windows 11 Pro 23H2 Build: 22631.4249
    Computer type
    Laptop
    Manufacturer/Model
    LENOVO Yoga 7i EVO OLED 14" Touchscreen i5 12 Core 16GB/512GB
    CPU
    Intel Core 12th Gen i5-1240P Processor (1.7 - 4.4GHz)
    Memory
    16GB LPDDR5 RAM
    Graphics card(s)
    Intel Iris Xe Graphics Processor
    Sound Card
    Optimized with Dolby Atmos®
    Screen Resolution
    QHD 2880 x 1800 OLED
    Hard Drives
    M.2 512GB
    Antivirus
    Defender / Malwarebytes
    Other Info
    …still on a horse.
Back
Top Bottom