Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Python 很陌生。我想根据名称而不是基于数据类型将一组文件从一个文件夹复制到另一个文件夹。所以我有一个源文件夹,其中包含 Hello.txt、Hello.dat、Hello.pdf、World.txt、World.dat、Word.pdf 等文件。现在我只想将以“Hello”开头的文件复制到另一个文件夹中。我尝试了很多方法,但似乎都基于数据类型。
import os import shutil files = os.listdir("Path") for file in files: if file.startswith("Hello"): shutil.copy("Full path to file", "Full path to dest folder")