定位一个文件并复制到另一个目录

发布于 2025-01-15 12:39:55 字数 318 浏览 2 评论 0原文

我正在开发一个使用 python 和 selenium webdriver 下载文件的机器人。我已经成功地设计了机器人并且它运行得很好。问题是

  1. 我想定位刚刚下载的这个文件。该程序将被许多人使用,他们可能设置了不同的下载目录。如何使用操作系统模块来实现这一目标?
  2. 从网站下载数据后,默认名称为交易;我的用户可能有其他同名文件,并且我的程序可能会复制错误的文件。该文件为 Excel 格式。

如何单独定位此文件而不是任何其他文件,即使它们具有相同的名称,或者是否有办法更改我的机器人保存它下载的任何文件的目录,这样我就不需要复制到我想要的目录它用于计算?

I am working on a bot that downloads a file using python and selenium webdriver. I have successfully been able to design the bot and it is working perfectly. The issue is

  1. I want to target this file that was just downloaded. This program is going to be used by many people who may have set different directory for downloads. How do I use the OS module to achieve this?
  2. Once the data is downloaded from the site, the default name is transactions; my users may have other files with the same name and my program might copy a wrong file. The file is in an excel format.

How do I target this file alone and not any other file even if they have the same name or is there a way I can change the directory my bot save any file it downloads so I don't need to copy to the directory where I want it for calculations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2025-01-22 12:39:55

考虑使用 Shutil

newfilename = os.path.join(os.path.abspath('foopath'), 'foofile') Shutil.copyfile('transactions', newfilename)

中的其他选项

参考复制文件-from-one-location-to- python中的另一个

consider use of shutil

newfilename = os.path.join(os.path.abspath('foopath'), 'foofile') shutil.copyfile('transactions', newfilename)

Reference other options at

copy-a-file-from-one-location-to-another-in-python

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文