欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python--音频文件分类代码

程序员文章站 2022-05-04 14:08:16
...

上代码:

import os
from shutil import copy2

SOURCE = "c:\\source\\"

DEST = "c:\\dest\\"

# Iterate recursively through all files and folders under the source directory
for path, dirs, files in os.walk(SOURCE):
    # For each directory iterate over the files
    for f in files:
        # Grab the first letter of the filename
        starting_letter = f[0].upper()
        # Construct the full path of the current source file
        source_path = os.path.join(path, f)
        # Construct the destination path using the first letter of the
        # filename as the folder
        dest_path = os.path.join(DEST, starting_letter)
        # Create the destination folder if it doesn't exist
        if not os.path.isdir(dest_path):
            os.makedirs(dest_path)
        # Copy the file to the destination path + starting_letter
        copy2(source_path, dest_path)