|

楼主 |
发表于 2025-1-29 19:10
|
显示全部楼层
本帖最后由 ning84 于 2025-1-29 21:28 编辑
- ''
- Function JpgFilesToDict(oFiles As Files, Dict As Scripting.Dictionary) As Scripting.Dictionary
- Dim oFile As File
- Kk = 1
- For Each oFile In oFiles
- With oFile
- '''
- If InStr(UCase(.Type), "JP") > 0 Then
- Set Dict(oFile.Path) = oFile
- End If
- End With
- Next oFile
- Set JpgFilesToDict = Dict
- End Function
复制代码
import os
def jpg_files_to_dict(folder_path):
jpg_dict = {}
for file_name in os.listdir(folder_path):
if file_name.upper().endswith('.JPG') or file_name.upper().endswith('.JPEG'):
file_path = os.path.join(folder_path, file_name)
jpg_dict[file_path] = file_name
return jpg_dict
# 示例用法
folder_path = '/path/to/your/folder' # 替换为你的文件夹路径
jpg_files = jpg_files_to_dict(folder_path)
print(jpg_files)
|
|