<> Method 1 :

Project name :InterfaceTest_master, root directory :InterfaceTest_master/
# Gets the directory of the current file cur_path = os.path.abspath(os.path.dirname(__file__)) # Get root directory
root_path= cur_path[:cur_path.find("InterfaceTest_master\\")+len(
"InterfaceTest_master\\")] print(root_path) # Create another directory data_path = os.path.abspath
(root_path +'\\excelReport') if not os.path.exists(data_path): os.mkdir(
data_path) # If this doesn't exist excelReport folder , Create one automatically print(data_path)
<> Operation results :
C:\Users\Administrator\Desktop\InterfaceTest_master\ C:
\Users\Administrator\Desktop\InterfaceTest_master\excelReport
<> Method 2 :
# Get root directory base_dir = dirname(dirname(abspath(__file__))) print(base_dir) #
Revised to linux catalog base_dir = base_dir.replace('\\', '/') print(base_dir) # Create another directory
file_path= base_dir + "/excelReport" print(file_path)
<> Operation results :
C:\Users\Administrator\Desktop\InterfaceTest_master C:/Users/Administrator/
Desktop/InterfaceTest_master C:/Users/Administrator/Desktop/InterfaceTest_master
/excelReport

Technology