As you know for server side swift Perfect 2.0 framework is out. I was trying to get path for root directory but didn't have any luck yet.
Snippet 1
let fileDir = Dir("/Resources/fileuploads")
print(fileDir.path)
this code give me path as
/Resources/fileuploads
Snippet 2
let fileDir = Dir(Dir.workingDir.path + "Resources/fileuploads")
print(fileDir.path)
this code gives me path as
/Users/username/Library/Developer/Xcode/DerivedData/projname-acxmbygsjkthxvbigpfoqesstidh/Build/Products/Debug/Resources/fileuploads/
However actual path where i want it, to point to is.
/Users/username/Documents/folderOne/folderTwo/projname/Resources/fileuploads/
where
/Users/username/Documents/folderOne/folderTwo/projname
is the path where my root folder of the project is located.
Question
how do i get path to root folder of the project ?
This works in Swift 3.1 and above
// As a string
let THIS_FILES_PATH:String = #file
print(THIS_FILES_PATH)
// As an array
let THIS_FILES_PATH_AS_ARRAY:[String] = #file.split(separator: "/").map({String($0)})
print(THIS_FILES_PATH_AS_ARRAY)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With