iT邦幫忙

0

如何用python取得檔案的詳細資料

  • 分享至 

  • xImage

有辦法取得檔案中的詳細資料嗎
https://ithelp.ithome.com.tw/upload/images/20210709/20123846MZVROj8TEH.png
我目前找不到什麼方法能抓到這個頁面的資料

看更多先前的討論...收起先前的討論...
haward79 iT邦研究生 2 級 ‧ 2021-07-10 01:01:04 檢舉
請參考:
https://stackoverflow.com/questions/40444334/get-url-file-property-from-a-windows-internet-shortcut-url-file
s4028600 iT邦新手 5 級 ‧ 2021-07-11 01:03:47 檢舉
這個url只是範例...
我要的不是檔案內容
是檔案的詳細資料
haward79 iT邦研究生 2 級 ‧ 2021-07-11 06:26:50 檢舉
那個詳細資料的內容會隨著檔案的類型而改變
所以基本上你要根據不同的檔案類型寫不同的程式
s4028600 iT邦新手 5 級 ‧ 2021-07-11 09:59:23 檢舉
沒有通則喔...
所以還是要讀取檔案內容來取得嗎
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
nwm310
iT邦新手 4 級 ‧ 2021-07-11 12:40:16
最佳解答

pip install pywin32

import win32com.client
import os.path

filePath = 'C:\\1.url'
folderPath = os.path.dirname(filePath)
fileName = os.path.basename(filePath)

shell = win32com.client.Dispatch('Shell.Application')
folder = shell.NameSpace(folderPath)
file =  folder.ParseName(fileName)
for i in range(-1, 330):
    folder.GetDetailsOf('', i)  , folder.GetDetailsOf(file, i)



s4028600 iT邦新手 5 級 ‧ 2021-07-11 13:31:58 檢舉

你的方法可以
但突然出現
AttributeError: '<win32com.gen_py.Microsoft Shell Controls And Automation.IShellDispatch6 instance at 0x1882104117568>' object has no attribute 'namespace'
後就不行了

nwm310 iT邦新手 4 級 ‧ 2021-07-11 17:26:44 檢舉

測試環境:Win10 + Python 3.7.4
namespace parsename getdetailsof
雖然這些字都是小寫的,但仍然可以正確執行

現在,已經把這些字改成正確的大小寫了
NameSpace ParseName GetDetailsOf
再試試看

s4028600 iT邦新手 5 級 ‧ 2021-07-11 22:15:40 檢舉

可以了
好奇怪的情況
感謝幫忙

自己的簡易改良

import win32com.client
import os.path

filePath = 'E:\\Users\\LONG\\Desktop\\2.png'
folderPath = os.path.dirname(filePath)
fileName = os.path.basename(filePath)

shell = win32com.client.Dispatch('Shell.Application')
folder = shell.NameSpace(folderPath)
file =  folder.ParseName(fileName)
for i in range(-1, 330):
    if folder.GetDetailsOf(file, i):
        print(folder.GetDetailsOf('', i),folder.GetDetailsOf(file, i),sep="\t\t")

我要發表回答

立即登入回答