0

我刚刚接到任务,为大约 500 个客户在盒子上创建一个新文件夹。Python 是我唯一熟悉的代码,但我也愿意使用另一种语言。我在 excel 中有每个客户名称的列表,如果可能的话,我想为每个名称创建一个新文件夹,其中包含子类别(例如插图、建议和会议记录)。然后,我会将所有这些放在一个文件夹中,然后将该一个大文件夹上传到盒子中。如果有人可以帮助,请告诉我

4

1 回答 1

0

如前所述,您应该调查该csv库,但如果这是一次性操作,并且看到只有 500 个客户端,则将 500 个客户端复制粘贴到以下脚本中可能会更简单:

import os

names = """
Adam Adams
Betty Bo 
 Carl Carter
Denise & David Daniels"""

sub_categories = ["Illustrations", "Advice", "Meeting Notes"]
root_folder = "c:/clients"

for name in names.split("\n"):
    # Sanitise the name (remove any extra leading or trailing spaces)
    name = name.strip()

    # Skip any blank lines
    if name:
        # Remove some illegal characters from the name (could be done using RegEx)
        for item in ["&", "/", "\\", ":"]:
            name = name.replace(item, " ")      # Convert to spaces

        name = name.replace("  ", "")           # Remove any double spaces

        # Create all the folders for this client name
        for sub_category in sub_categories:
            os.makedirs("%s/%s/%s" % (root_folder, name, sub_category))

在 Python 2.7 中测试

于 2015-07-06T15:28:24.613 回答