Найти - Пользователи
Полная версия: Функция проверки директории на наличие
Начало » Python для новичков » Функция проверки директории на наличие
1
Ubhra
Добрый день.
По клику работает функция:
def event_1(event):
    if os.access(os.getcwd() + '/site/node', os.F_OK) and os.access(os.getcwd() + '/site/export', os.F_OK):
        text_out.delete('1.0', 'end')
        text_out.insert('1.0', 'folder NODE and EXPORT - OK\n\v')
    else:
        text_out.delete('1.0', 'end')
        text_out.insert('1.0', 'folder - ERROR\n')
    if os.access(os.getcwd() + '/site/node/2016', os.F_OK):
        text_out.insert('1.0', '2016\n')
    else:
        text_out.insert('1.0', 'folder 2016 - ERROR\n')
    if os.access(os.getcwd() + '/site/node/2016/04', os.F_OK):
        text_out.insert('1.0', '\tERROR no 04 folder\n')
    else:
        text_out.insert('1.0', '\t04 april\n')
    if os.access(os.getcwd() + '/site/node/2016/05', os.F_OK):
        text_out.insert('1.0', '\tERROR no 05 folder\n')
    else:
        text_out.insert('1.0', '\t05 april\n')
    if os.access(os.getcwd() + '/site/node/2016/06', os.F_OK):
        text_out.insert('1.0', '\tERROR no 06 folder\n')
    else:
        text_out.insert('1.0', '\t06 april\n')
    if os.access(os.getcwd() + '/site/node/2016/07', os.F_OK):
        text_out.insert('1.0', '\tERROR no 07 folder\n')
    else:
        text_out.insert('1.0', '\t07 april\n')
    if os.access(os.getcwd() + '/site/node/2016/08', os.F_OK):
        text_out.insert('1.0', '\tERROR no 08 folder\n')
    else:
        text_out.insert('1.0', '\t08 april\n')
    if os.access(os.getcwd() + '/site/node/2016/09', os.F_OK):
        text_out.insert('1.0', '\tERROR no 09 folder\n')
    else:
        text_out.insert('1.0', '\t09 april\n')
    if os.access(os.getcwd() + '/site/node/2016/10', os.F_OK):
        text_out.insert('1.0', '\tERROR no 10 folder\n')
    else:
        text_out.insert('1.0', '\t10 april\n')
    if os.access(os.getcwd() + '/site/node/2016/11', os.F_OK):
        text_out.insert('1.0', '\tERROR no 11 folder\n')
    else:
        text_out.insert('1.0', '\t11 april\n')
    if os.access(os.getcwd() + '/site/node/2016/12', os.F_OK):
        text_out.insert('1.0', '\tERROR no 12 folder\n')
    else:
        text_out.insert('1.0', '\t12 april\n')

И выводит такой результат:
ERROR no 12 folder
ERROR no 11 folder
ERROR no 10 folder
ERROR no 09 folder
ERROR no 08 folder
ERROR no 07 folder
ERROR no 06 folder
ERROR no 05 folder
ERROR no 04 folder
2016
folder NODE and EXPORT - OK

Если написать так:
 if os.access(os.getcwd() + '/site/node/2016/09', os.F_OK):
        print('ok')
    else:
        print('no')
То все работает.

Почему не видит директории и начинает печатать с конца?

А еще что это за символ во вложении?
П.С. Насчет символа неизвестного разобрался. Это вертикальная табуляция криво отработала.
Ubhra
Разобрался. Идиот перепутал местами варианты условия ))
doza_and
Ubhra
Почему не видит директории
Так вы к сообщению директории не приложили. Как мы должны разбираться.
Однозначно надо использовать os.path.exists, os.path.join и конечно for и format или golob или listdir
FishHook
Всегда, когда вижу такие портянки китайского кода возникает один и тот жен вопрос: самого то не задолбало одно и то же копипастить?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB