0

I am trying to list the files present in the input folder:

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

And I am getting this error (Using Python 3):

C:\Users\Tristan\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)
    988                                          env,
    989                                          cwd,
--> 990                                          startupinfo)
    991             finally:
    992                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified
RoyaumeIX
  • 1,947
  • 4
  • 13
  • 37

2 Answers2

2

ls doesn't exist as a command in windows, hence the error; it can't find an executable named ls to run. The solutions to this similar question should help you do what you want: How to use Subprocess in Windows

Izaak Weiss
  • 1,281
  • 9
  • 18
0

Thanks to Izaak Weiss answer, the solution becomes:

import os
l = os.listdir("input")
print (l)
RoyaumeIX
  • 1,947
  • 4
  • 13
  • 37