简体   繁体   中英

FileNotFoundError: [WinError 3] The system cannot find the path specified '\\xml\\'

Script will pick the xml file from XML folder and parse it, it is running great when I run .py file directly. But, when I call the .py using .bat file I am getting below errors.

XML.bat

@ECHO OFF
REM A batch script to execute a Python script
SET PATH=%PATH%;C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.6
py GET_XML.py
PAUSE

Python snippet for getting file name under xml folder

import os
pathx = (os.path.dirname(__file__)+str('\\xml\\'))
list1 = os.listdir(pathx)
#GET Folder
#print(pathx)
paths = (''.join(map(str,list1)))
#GET Files inside Folder
#print(paths)
#Insert in xml parse
tree = ET.parse(paths)
root = tree.getroot()

Error

在此处输入图片说明

Directory Structure

Python(folder)   
  +GET_XML.py
  +XML.bat
  +XML (folder)
      +1231.xml

It is more reliable to join paths using os.path.join , it will take care of escaping the characters and pick the path separator for your system. Try to use the following line:

pathx = (os.path.join(os.path.dirname(__file__), 'xml'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM