I'm receiving the following error while trying to grab File Permissions/attributes. I haven't been able to find anything that has helped. Any idea would be great.
pywintypes.error: (123, 'GetFileAttributes', 'The filename, directory name, or volume label syntax is incorrect.')
Here is the code I'm using.
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)
Here is the exact copy from the terminal.
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
Process finished with exit code 1
Check the last line on the traceback (or first depending on how you look at it). Your dir
and dirName
variables appear to return the same string. You're concatenating the same string twice plus the file name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.