4
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?

Anh Pham
  • 2,108
  • 9
  • 18
  • 29
IuBr
  • 43
  • 1
  • 1
  • 3
  • Look into [`os.path.isdir`](https://docs.python.org/2/library/os.path.html#os.path.isdir) – Himal Jul 14 '17 at 08:06

2 Answers2

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

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Sirine Attia
  • 131
  • 1
  • 3
0

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

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100