I'm trying to determine if a file object is a directory. According to the docs, the function isDirectory can only be used on Android and MobileWeb. How can I do this on iOS?
2 Answers
Accepted Answer
file.nativePath will be ended with / if it was a directory.. You can determine if a file object is a directory or not based on that characteristic :)
Here're sample patterns:
// [INFO] file://localhost/Users/minh/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/0C123CA6-4B4E-4027-B2D6-10080F9ECD86/hw.app/dir/ // [INFO] file://localhost/Users/minh/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/0C123CA6-4B4E-4027-B2D6-10080F9ECD86/hw.app/file_without_extention
Here is a quick function for cross platform checking of directories
var isDirectory = function(file) { if(Ti.Platform.osname === 'ipad' || Ti.Platform.osname === 'iphone') { return file.nativePath.lastIndexOf('/') === file.nativePath.length-1; } return file.isDirectory(); };
Your Answer
Think you can help? Login to answer this question!