如何使用python获取有关文件的“属性”>“详细信息”的信息?

时间:2018-07-12 06:53:06

标签: python win32com

到目前为止,我仅成功获得了使用此代码的版本。

from win32com.client import Dispatch    
ver_parser = Dispatch('Scripting.FileSystemObject')
info = ver_parser.GetFileVersion(path + "\\" + file)

现在,我所知道的就是“ GetFileVersion”,并且我的IDE不会自动完成以向我显示其他选项来补充其他信息

样本文件属性>详细信息:

enter image description here

3 个答案:

答案 0 :(得分:0)

根据this site,您需要使用COM浏览器来查看哪些方法和属性可用。

对于最基本的方法,请执行以下操作:

from win32com.client import combrowse
combrowse.main()

答案 1 :(得分:0)

我认为您可以使用“ Shell.Application”获取文件元信息。如下所示替换文件夹名和文件名。

from win32com.client import Dispatch
shell = Dispatch("Shell.Application")
_dict = {}
# enter directory where your file is located
ns = shell.NameSpace("D:\\Userfiles\\Downloads")
for i in ns.Items():
    # Check here with the specific filename
    if str(i) == "Test.png":
        for j in range(0,49):
            _dict[ns.GetDetailsOf(j,j)] = ns.GetDetailsOf(i,j)

print _dict

答案 2 :(得分:0)

您可以使用> BUILD FAILED in 1s > at ChildProcess.whenDone (D:\myproyects\ionicproyect proyectos\myapp\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23) > at emitTwo (events.js:126:13) > at ChildProcess.emit (events.js:214:7) > at maybeClose (internal/child_process.js:925:16) > at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) (node:1492) > UnhandledPromiseRejectionWarning: Unhandled promise rejection. This > error originated either by throwing inside of an async function > without a catch block, or by rejecting a promise which was not handled > with .catch(). (rejection id: 1) (node:1492) [DEP0018] > DeprecationWarning: Unhandled promise rejections are deprecated. In > the future, promise rejections that are not handled will terminate the > Node.js process with a non-zero exit code. 生成与COM模块相对应的Python代码。这样,您可以使用__dir__来访问所有方法的名称(并且您的IDE可能会使用win32com.client.gencache.EnsureDispatch自动完成代码,以便您也可以这样做);

__dir__

请注意,这只会为您提供方法的名称,而不是属性(yet)的名称,但是您可以手动获得这些名称:

In [204]: from win32com.client.gencache import EnsureDispatch

In [205]: ver_parser = EnsureDispatch('Scripting.FileSystemObject')

In [210]: [a for a in ver_parser.__dir__() if '_' not in a]
Out[210]:
['CLSID',
 'BuildPath',
 'CopyFile',
 'CopyFolder',
 'CreateFolder',
 'CreateTextFile',
 'DeleteFile',
 'DeleteFolder',
 'DriveExists',
 'FileExists',
 'FolderExists',
 'GetAbsolutePathName',
 'GetBaseName',
 'GetDrive',
 'GetDriveName',
 'GetExtensionName',
 'GetFile',
 'GetFileName',
 'GetFileVersion',
 'GetFolder',
 'GetParentFolderName',
 'GetSpecialFolder',
 'GetStandardStream',
 'GetTempName',
 'MoveFile',
 'MoveFolder',
 'OpenTextFile']

相关的堆栈溢出问题: