Python中的条件格式文件夹

2024-09-30 22:16:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个脚本,该脚本将使用文件夹标记更改windows文件夹的颜色。我正在使用Excel中的条件单元格示例。如果子文件夹中有文件,我希望将文件夹变为绿色,否则变为红色

我几乎没有使用python或任何其他脚本语言的经验,我完全迷路了。这是我到目前为止得到的

import os
import subprocess
from os import walk, rename
from subprocess import call

#if/else statements for setting folder color based on number of songs in each folder

directory = 'E:\Projects\Ableton\Finished Tracks\2 Finished'            #detailing the directory for the script to run
for folder, subfolders, filenames in os.walk(directory):                #idk what this does, i saw it on stack
    if any([filename.endswith('.wav') for filename in filenames]):                      #searching for any songs in the directory
        FolderMarker = 'C:\Program Files (x86)\Folder Marker\\FolderMarker.exe'         #detailing file path for FolderMarker
        call(["C:\Program Files (x86)\Folder Marker\FolderMarker.exe"])                 #launching FolderMarker if true

我尝试使用os.startfile


Tags: theinfromimport脚本文件夹forif