OSError: [Errno 20] Not a directory, .DS_Store
Asked Answered
C

2

5
BASE_FOLDER = "/Users/User/Desktop/DATA"
BOOK_GROUP_FOLDER = os.path.join(BASE_FOLDER, "book_group")
SCREEN_GROUP_FOLDER = os.path.join(BASE_FOLDER, "screen_group")
hidden_file = ("/Users/User/Desktop/DATA/book_group/.DS_Store")

def listdir_ignorehidden(path): #Ignore HiddenFiles
    for f in os.listdir(hidden_file):
        if not f.startswith ('.') and os.path.isfile(os.path.join(hidden_file , f)):
            yield f

def get_person_folder_reading(persons_folder, screen_type):
    base_folder = os.path.join(persons_folder, screen_type)
    return [os.path.join(base_folder, fn) for fn in os.listdir(base_folder) if fn not in ["test", ".Data", "._.Data"]][0]

OSError: [Errno 20] Not a directory: '/Users/User/Desktop/DATA/book_group/.DS_Store/eye_tracker/paper'

I am trying to read multiple files from different directories. However I get an error that seems to be caused by mac's .DS_Store. I defined a function that should ignore it, but it doesn't help.

Any ideas how to handle it?

Curvy answered 14/7, 2017 at 3:5 Comment(1)
Look into os.path.isdirGhiberti
Z
1

It's not a problem with .DS_STORE, it's because you're assuming all entries in a directory are a directory. You should check whether an entry is a directory before running listdir() on it

Zara answered 14/7, 2017 at 8:4 Comment(0)
B
10

I've done this in my workspace terminal and now it works for me :

find . -name "*.DS_Store" -type f -delete

link: https://github.com/mapbox/robosat/issues/47

Bulletin answered 27/3, 2019 at 14:39 Comment(0)
Z
1

It's not a problem with .DS_STORE, it's because you're assuming all entries in a directory are a directory. You should check whether an entry is a directory before running listdir() on it

Zara answered 14/7, 2017 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.