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:
JavaScript
x
3
1
from subprocess import check_output
2
print(check_output(["ls","../input"]).decode('utf8'))
3
this is the error i have received:
JavaScript
1
36
36
1
FileNotFoundError Traceback (most recent call last)
2
<ipython-input-15-c18143c64098> in <module>
3
1 from subprocess import check_output
4
----> 2 print(check_output(["ls","../input"]).decode('utf8'))
5
6
~Anaconda3libsubprocess.py in check_output(timeout, *popenargs, **kwargs)
7
393
8
394 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
9
--> 395 **kwargs).stdout
10
396
11
397
12
13
~Anaconda3libsubprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
14
470 kwargs['stderr'] = PIPE
15
471
16
--> 472 with Popen(*popenargs, **kwargs) as process:
17
473 try:
18
474 stdout, stderr = process.communicate(input, timeout=timeout)
19
20
~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)
21
773 c2pread, c2pwrite,
22
774 errread, errwrite,
23
--> 775 restore_signals, start_new_session)
24
776 except:
25
777 # Cleanup if the child failed starting.
26
27
~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)
28
1176 env,
29
1177 os.fspath(cwd) if cwd is not None else None,
30
-> 1178 startupinfo)
31
1179 finally:
32
1180 # Child is launched. Close the parent's copy of those pipe
33
34
FileNotFoundError: [WinError 2] The system cannot find the file specified
35
36
Advertisement
Answer
You can get a list of all the files in the current directory by doing this:
JavaScript
1
3
1
import os
2
files = os.listdir('./')
3