Home>

wrote a code that would generate various folders to me. It is assumed that the code will create a folder, and within her file. Then, open the file and record content in it:

filename= airline ["IATA"] + '/index.php'
if not os.path.Exists (os.path.dirname (FileName)):
    OS.Makedirs (FileName)
    With Open (FileName, "W") AS F:
        F.Write ("<
? PHP Include ('generator.php'); ? ≫
")

In the end, the folder should turn out AA /index.php. but instead of creating a file I have a nested folder called index.php. . How do I do so that the file is created in the newly created folder and write down in it?

You pass Filename to Makedirs-here and creating an index.php folder, since you pass the name with the extension.

And2021-04-09 09:35:37
  • Answer # 1

    in Makedirs. You need to pass the folder:

    filename= airline ["IATA"] + '/index.php'
    if not os.path.Exists (os.path.dirname (FileName)):
        dir_name= os.path.dirname (FileName)
        OS.Makedirs (Dir_Name)
        With Open (FileName, "W") AS F:
            F.Write ("<
    ? PHP Include ('generator.php'); ? ≫
    ")