Reputation: 85
I'm having trouble to run a Python script by a batch file. One of my program features is to access a folder with some files in it and get the name of them. For this task, I'm using .walk() from os library. When I run my program manually in the command prompt it works perfectly and return for me a list with the files. But when I run by a batch file they return form me an empty list. Can you guys give me a help? Please?
batch file:
@ECHO ON
"C:\Users\Anaconda3\python.exe" "C:\Users\my_program\__main__.py"
ECHO Done.
PAUSE
enter code here
Python program:
'''Works fine when I start the program manually in the command prompt. But running
by a batch file is returning for me a empty list. '''
input_path = getcwd() + "\\input"
list_files = [x[2] for x in os.walk(input_path)]
print(">>> Test Batch: ", input_path) # it's printing the path of the folder correctly
print(">>> Test Batch2: ", list_files) # it's printing a empty list
Upvotes: 1
Views: 1289
Reputation: 175
I believe in this instance getcwd would be returning the directory from which you started the batch file, not the directory of the batch file or the directory of the python file. My advice is to print the value of input_path and the issue will become clear.
Upvotes: 3