0
我在嘗試獲取文件權限/屬性時收到以下錯誤。我一直無法找到任何有幫助的東西。任何想法都會很棒。Python win32api GetFileAttributes
pywintypes.error: (123, 'GetFileAttributes', 'The filename, directory name, or volume label syntax is incorrect.')
這是我使用的代碼。
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