SoFunction
Updated on 2024-10-29

The python method to get the path of the current file and the path of the parent file.

# Path to the current file
pwd = ()
#Parent path of the current file
father_path=((pwd)++".")
# The first two directory levels of the current file
grader_father=((pwd)++"..")

Additional partial code examples

def TestPrtPwd(self):
    print("Get current file path -" + (__file__)) # Get the current file path
    parent = ((__file__))
    print("Get its parent catalog--" + parent) # Get the directory from the current file path
    garder = (parent)
    print("Get the parent directory of the parent directory -" + garder)
    print("Get filename" + ((__file__))) # Get filename
    # Path to the current file
    pwd = ()
    print("Path to current running file" + pwd)
    # Parent path of the current file
    father_path = ((pwd) +  + ".")
    print("Parent path of the run file" + father_path)
    # The first two directory levels of the current file
    grader_father = ((pwd) +  + "..")
    print("Parent path of the parent path of the run file" + grader_father)
    return garder

Run results:

Get current file path——D:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData\common\
Get its parent directory——D:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData\common
Get the parent directory of the parent directory——D:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData
Get filename
Path to the current running fileD:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData\TestSuite\RoleManagement
Parent path of the runtime fileD:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData\TestSuite
Parent path of the runtime file的父路径D:\SVN\test (machinery etc)\autotest\functionalAutomation\aonr_sxsj\AuditData

Above this python to get the current file path and the parent file path is all I have shared with you, I hope to give you a reference, and I hope you support me more.