I am trying to read the csv files in the current directory. In-order to do that, I want to check all the files present in my current directory. I have tried doing it with check_output function. However, i received this error and I’m unable to figure out how to deal with it. This is the code I have tried:
from subprocess import check_output print(check_output(["ls","../input"]).decode('utf8'))
this is the error i have received:
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')) ~Anaconda3libsubprocess.py in check_output(timeout, *popenargs, **kwargs) 393 394 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, --> 395 **kwargs).stdout 396 397 ~Anaconda3libsubprocess.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) ~Anaconda3libsubprocess.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. ~Anaconda3libsubprocess.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
Advertisement
Answer
You can get a list of all the files in the current directory by doing this:
import os files = os.listdir('./')