【发布时间】:2021-10-15 00:00:18
【问题描述】:
我无法通过批处理文件运行 Python 脚本。 我的程序功能之一是访问其中包含一些文件的文件夹 并得到他们的名字。对于这个任务,我使用 .walk() 来自操作系统库。当我在命令提示符下手动运行我的程序时 它工作得很好,并为我返回了一个包含文件的列表。 但是当我通过批处理文件运行时,它们会向我返回一个空列表。 你们能帮帮我吗?请问?
批处理文件:
@ECHO ON
"C:\Users\Anaconda3\python.exe" "C:\Users\my_program\__main__.py"
ECHO Done.
PAUSE
enter code here
Python 程序:
'''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
【问题讨论】:
-
批处理文件在哪里?在您的批处理文件中添加
echo %cd%以获取打印批处理文件的当前目录
标签: python batch-file