python - 使用带有字典值的 .find 来组织文件
问题描述
import os
import shutil
# path to downloads
downloadPath = 'C:\\Users\\USER\\Downloads\\'
# creates a list of all download files
downloadFileList = os.listdir(downloadPath)
# path to companies
companyPath = 'C:\\Users\\USER\\Documents\\Companies\\'
# creates a list of the company folders
companyFolderList = os.listdir(companyPath)
# creates a list of company folder addresses
CompanyDict = {'Company': 'Path'}
# Make a dictionary that has the company key and path values
for company in companyFolderList:
CompanyDict.update({company: f'C:\\Users\\USER\\Documents\\Companies\\' + company})
print(CompanyDict)
for download in downloadFileList:
if download.find(str(CompanyDict.items())) >= 1:
shutil.move(f'C:\\Users\\USER\\Downloads' + download, f'C:\\Users\\USER\\Documents\\Companies' + download)
print(download + ' has been moved into the Documents Folder')
else:
print(download + " has not been moved")
因此,我正在尝试制作一个程序,该程序将查看我的下载文件夹中是否有包含特定公司名称的文档,然后如果有匹配项,则将它们移动到公司文件夹。
发生的事情是 for 循环和 if 函数似乎没有拾取我留在下载文件夹中的一些文件作为测试。例如,其中一个输出是
Canon TEST.csv has not been moved
即使我的公司文件夹中有一个佳能文件夹。
任何帮助,将不胜感激
解决方案
推荐阅读
- docker - 在 Docker 中使用私有模块构建 Go 应用程序
- javascript - 如何在 JavaScript 中通过 read 方法使用 RPC 查询,从表中获取所有行。在 Odoo 13 中?
- javascript - 单选按钮值选择器
- core-data - 如何在 Swift 中将 NSPredicate 与计算属性一起使用?
- python-3.x - 使用第一列作为索引合并 2 个数据框
- spring - 从 BOM 跟踪 jar
- ios - SwiftUI 错误找不到类型为 GlobalEnvironment 的 ObservableObject
- html - 我的网络应用程序中的图像未显示但已正确添加
- r - r 操作序列的字符向量
- python - 如何让熊猫的 timedeltas 时区感知?