Я не могу проверить файлы, доступные в каталоге - PullRequest
0 голосов
/ 12 июля 2020

Я пытаюсь прочитать файлы csv в текущем каталоге. Для этого я хочу проверить все файлы, присутствующие в моем текущем каталоге. Я пробовал делать это с помощью функции check_output. Однако я получил эту ошибку и не могу понять, как с ней бороться. Это код, который я пробовал:

from subprocess import check_output
print(check_output(["ls","../input"]).decode('utf8'))

это полученная мной ошибка:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-15-c18143c64098> in <module>
      1 from subprocess import check_output
----> 2 print(check_output(["ls","../input"]).decode('utf8'))

~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    393 
    394     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 395                **kwargs).stdout
    396 
    397 

~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    470         kwargs['stderr'] = PIPE
    471 
--> 472     with Popen(*popenargs, **kwargs) as process:
    473         try:
    474             stdout, stderr = process.communicate(input, timeout=timeout)

~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    773                                 c2pread, c2pwrite,
    774                                 errread, errwrite,
--> 775                                 restore_signals, start_new_session)
    776         except:
    777             # Cleanup if the child failed starting.

~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1176                                          env,
   1177                                          os.fspath(cwd) if cwd is not None else None,
-> 1178                                          startupinfo)
   1179             finally:
   1180                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

1 Ответ

0 голосов
/ 12 июля 2020

Вы можете получить список всех файлов в текущем каталоге, выполнив следующие действия:

import os
files = os.listdir('./')
...