Python win32api GetFileAttributes

时间:2017-02-14 05:49:58

标签: python winapi

我在尝试获取文件权限/属性时收到以下错误。我还没能找到任何有帮助的东西。任何想法都会很棒。

  

pywintypes.error:(123,' GetFileAttributes','文件名,目录名或卷标语法不正确。')

以下是我正在使用的代码。

def getfileinfo(dir, ignoreddirs):
""" Loops through the directory and sub directories to get File Attributre Info """
print("Starting File Checks.")
for dirName, subDirList, fileList in os.walk(dir):
    # lets remove the ignored dirs from the subDirList
    for i in range(len(subDirList)):
        for x in range(len(ignoreddirs)):
            if subDirList[i] == ignoreddirs[x]:
                del subDirList[i]
    # Lets continue looping through
    print("We are in: %s" % dirName)

    for fname in fileList:
        print("We are checking file %s" % fname)
        # lets join the dir, dirname and filename
        file = dir + dirName + "\\" + fname
        print(file)
        # use win32api to get the Attributes
        att = win32api.GetFileAttributes(file)
        print("Attributes for this file is: " + att)

以下是终端的确切副本。

Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/yyy/main.py", line 26, in <module>
start()
File "C:/Users/xxx/PycharmProjects/yyy/main.py", line 19, in start
getfileinfo(dir, ignoreddirs)
File "C:\Users\xxx\PycharmProjects\yyy\permissionchecker.py", line 29, in  getfileinfo
att = win32api.GetFileAttributes(file)
pywintypes.error: (123, 'GetFileAttributes', 'The filename, directory name, or volume label syntax is incorrect.')
Starting File Checks.
We are in: C:\Users\crzyo\Desktop\EcoPC_0.4.2
We are checking file Eco.exe
C:\Users\xxx\Desktop\EcoPC_0.4.2C:\Users\crzyo\Desktop\EcoPC_0.4.2\Eco.exe

使用退出代码1完成处理

1 个答案:

答案 0 :(得分:1)

检查回溯的最后一行(或首先取决于你如何看待它)。您的dirdirName变量似乎返回相同的字符串。您将相同的字符串连接两次加上文件名。

相关问题