I have the following project layout (contracted):
project_root
└── Sources
└── App
├── main.swift
└── Models
└── SQL
└── createTables.sql
I'm trying to read the createTables.sql file at runtime but FileManager.fileExists() says it doesn't exist. I got the path by using #file in main.swift:
let path = URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Models/SQL/createTables.sql"
Printing out the path, it seems to be correct. I'm guessing that the source tree is inaccessible because of Heroku's ephemeral filesystem. How can I get around this and read the file at runtime?
Use
drop.workdirto get the project directory after compile time.Note I've also moved your file out of
Sourcesand intoResources. Vapor's project layout isn't set in stone, but currently the rule appears to be that the former is for Swift files and the latter for ancillary files.