Quantcast
Channel: Total Commander
Viewing all articles
Browse latest Browse all 3808

Total Commander (English) • Re: Change of substring in file names

$
0
0
You can accomplish this task using a scripting language like Python. Here's a Python script that renames files in bulk according to your specifications:

Code:

 import osimport re# Define the directory containing the filesdirectory = "/path/to/your/directory"# Define the regex pattern to extract the number from the filenamepattern = re.compile(r"#Tableau Course #(\d{1,3})\.mkv$")# Iterate over each file in the directoryfor filename in os.listdir(directory):    # Check if the file is an MKV file    if filename.endswith(".mkv"):        # Extract the number from the filename        match = re.search(pattern, filename)        if match:            number = match.group(1)            # Rename the file            new_filename = f"{number.zfill(3)} {filename.replace('#Tableau Course #' + number, '').strip()}"            os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename))            print(f"Renamed {filename} to {new_filename}")
Make sure to replace "/path/to/your/directory" with the path to the directory containing your files.
This script extracts the number from the filename using a regular expression, formats it to be zero-padded to 3 digits, and then inserts it at the beginning of the filename.
Fine thanls dear friend :shock: :) :D :wink: .

Att.

DruidCtba®.

Statistics: Posted by DruidCtba — 2024-04-30, 20:52 UTC



Viewing all articles
Browse latest Browse all 3808

Trending Articles