Windows批处理文件无法从使用的python文件中找到子文件

2024-09-19 23:36:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个批处理文件来启动多个.py文件,这些文件创建了一个地理数据库+要素类(带有域)。.py使用第二个/sub.py文件和.csv文件来获取他的输入

我失败了,因为.bat找不到这个.csv。我错过了什么

当前的.bat代码:

@echo on
"c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" "C:\Users\<restofthepath>\mainfile.py"
Pause

文件及;地图结构如下:

The file & map structure are the following:

我在*.bat文件中添加了“call”,虽然脚本中的暂停现在工作正常,但仍然出现以下错误:

Traceback (most recent call last):   

    File "C:\Users\<restofthepath>\mainfile.py", line 52, in <module> with open(<theCSVfile>) as infile: FileNotFoundError: [Errno 2] No such file or directory: <nameofthecsvfile>.csv'

主脚本中的第52行包含以下行:

with open(<theCSVfile>) as infile:
    mw_fields  = csv.DictReader(infile, delimiter = ';')

我是否需要将此“csv.Dictreader”也添加到我的.bat文件中?(可能我误解了.batfile的功能)

每个文件夹中都有一个主文件(和子文件)


Tags: 文件csvpy脚本aswithopencall
1条回答
网友
1楼 · 发布于 2024-09-19 23:36:23

将控件传递给第二个批处理文件propy时,控件将不会返回到原始批处理文件,因为您没有使用call关键字

请尝试:

@echo on
call "c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" "C:\Users\<restofthepath>\mainfile.py"
Pause

call的意思是“当另一个文件完成时,回来继续执行这个文件。”

相关问题 更多 >