Reputation: 15
I was creating a program that checked for files in my Downloads folder and moved them in some subfolders depending on their extention.
I used os.walk("path")
# path is the path to my downloads folder
and printed the files it found, just to see if it worked.
The problem is that the program finds the files in the folder, but it also finds some files that aren't there, most of them end with .zpa, and it also finds a desktop.ini file.
Is this normal or is there something wrong?
Upvotes: 0
Views: 786
Reputation: 177546
os.walk
will find all files including those marked with hidden and system attributes. Those files are not displayed by default in the Windows Explorer or the command line dir
utility.
If you want to skip hidden and system files in Python you'll have to check for the file attributes:
import os
import stat
for path,dirs,files in os.walk('Downloads'):
for file in files:
filename = os.path.join(path,file)
info = os.stat(filename)
if not info.st_file_attributes & (stat.FILE_ATTRIBUTE_SYSTEM | stat.FILE_ATTRIBUTE_HIDDEN):
print(filename)
Upvotes: 1
Reputation: 492
See os.walk
finds all files inside a directory. Those files which are hidden in Windows file explorer are also found out by this. Hidden files can include
Probably there can be files from the above category which you got to see in the output.
As far as .zpa
files are concerned, I don't know about those, but found a link which could help you.
Upvotes: 1