在Python上,我需要帮助搜索具有特定标题类型(PST文件,标题序列21 42 44 4E)的文件,然后将它们复制到我保存的文件目录中。基于标题的Python复制文件
以下是我的代码的相关摘录。
# get working directory of my program
ori_path=os.getcwd()
# this is where the file is saved(from the root directory of my program)
temp = "\etc\Saved Files"
# obtain value written in textbox, the path to search
path_to_copy_from=self.textbox.GetValue()
# create the absolute destination path so that the files don't end up somewhere they shouldn't be
copy_path="{}{}".format(ori_path,temp)
# change working directory to the one specified by user
os.chdir(path_to_copy_from)
我将使用shutil做像这样的复制:
shutil.copy(files,copy_path)
一些搜索,我发现使用itertools提及,但我不明白的例子(因此,为什么我是问题)。我需要帮助来找到将查看文件头的代码,然后在头与PST头格式匹配时调用shutil。
感谢@Junuxx等。你的代码专门针对一个文件,但我提供的路径是一个目录。但是,通过使用glob我可以在目录中的文件上运行此代码。非常喜欢 – KishanPD