Yoda-Canada / Magic-SSG

MIT License
0 stars 3 forks source link

Output file creation error when using directory input #2

Open lmpham1 opened 3 years ago

lmpham1 commented 3 years ago

Command

python magic_ssg.py --input sample"

Input Folder Structure

image

Error

Traceback (most recent call last):
  File "D:\Seneca\7th_Term\DPS909\New folder\Magic-SSG\magic_ssg.py", line 116, in <module>
    main()
  File "D:\Seneca\7th_Term\DPS909\New folder\Magic-SSG\magic_ssg.py", line 113, in main
    output_result(file, html)
  File "D:\Seneca\7th_Term\DPS909\New folder\Magic-SSG\magic_ssg.py", line 85, in output_result       
    with open(file_path, "w", encoding="utf8") as output_file:
FileNotFoundError: [Errno 2] No such file or directory: 'dist/sample/Silver Blaze.html'

Description:

The program is trying to create dist/sample/Silver Blaze.html file, but the dist/sample folder doesn't exist, so the error is produced. To fix this, dist/sample needs to be created first, before trying to open/create the HTML file. This can be done using the os.makedirs() command (check documentation).

On a side note, since Silver Blaze.html is directly under sample, which is the input folder, it should be generated directly under dist. The input folder should not be re-created inside the output folder, only its file structure and subfolders need to be replicated. For example:

input folder image

output folder image

To do this, you can try getting the path from the input folder to the file using os.walk and os.path.join, and then recreate the subfolders inside the output folder using os.makedirs(), before calling open() to create and write to the HTML files.