我有一个目录C:\HotFolders,其中应用程序每15分钟写入一次csv文件,文件名格式为YYYYMMDDhhmmss_DG@001991.csv.
我需要复制新文件(在创建新文件时),并将它们粘贴到另一个目录中,只需对文件名(_dgto _GWL)做一点小小的更改
我最初尝试制作一个SSMS包 (此处描述:https://jimsalasek.com/2017/03/15/ssis-create-extract-file-with-date-and-time-for-a-filename/) 要查询SQL数据库,请生成相同的文件并导出到目录,但SQL版本控制问题导致在SSMS中运行SSIS包(.dtsx文件)暂时无法运行
我尝试了一些python脚本来实现这一点(见下文),但扫描目录以查找最新的文件、复制并按计划粘贴重命名的文件(比如每5分钟一次)让我陷入了困境
我知道批处理和powershell也是可选的,甚至第三方软件,我也欢迎使用。我只需要一些关于最佳方法的指导,任何代码都会很感激
Python代码片段
import os
files = [os.path.join('C:\\test', x) for x in os.listdir('C:\\test') if x.endswith(".csv")]
newest = max(files , key = os.path.getctime)```
评注应足以解释
希望我能很好地理解,这就是你想要的:
请让我知道这是否是你一直在寻找的,如果你想了解发生在这个短脚本块;我非常乐意解释(只是不想假设你还不知道一切)
哎呀,刚刚意识到你想复制这些项目:
请注意:您还可以按csv或
-Filter
参数提供的任何其他文件扩展名进行筛选相关问题 更多 >
编程相关推荐