定位一个文件并复制到另一个目录
我正在开发一个使用 python 和 selenium webdriver 下载文件的机器人。我已经成功地设计了机器人并且它运行得很好。问题是
- 我想定位刚刚下载的这个文件。该程序将被许多人使用,他们可能设置了不同的下载目录。如何使用操作系统模块来实现这一目标?
- 从网站下载数据后,默认名称为交易;我的用户可能有其他同名文件,并且我的程序可能会复制错误的文件。该文件为 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
- 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?
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用 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