2011-01-07 1 views
0

appcelarator titanium을 사용하는 iPad 앱을 개발 중이며 디렉토리 내용을 반복하고 포함 된 항목의 유형 (파일인지 디렉토리인지 여부)을 결정해야합니다.Appcelerator Titanium에서 File.isFile 및 File.isDirectory가 제대로 작동하지 않습니까?

dirFullPath = '/full/path/to/directory'; 
var dir = Titanium.Filesystem.getFile(dirFullPath); 
var dirItems = dir.getDirectoryListing(); 
for (var i=0; i<dir.length; i++) { 
    itemFullPath = dirFullPath 
       + Titanium.Filesystem.getSeparator() 
       + dir[i].toString(); 
    testItem = Titanium.Filesystem.getFile(itemFullPath); 
    if (testItem.exists()) { 
     alert(itemFullPath + ' exists.');    // item exists, alert box appears 
     if (testItem.isDirectory) {    
      alert(itemFullPath + ' is a directory.'); // this code is never executed 
     } 
     else if (testItem.isFile) { 
      alert(itemFullPath + ' is a file.');  // this code is never executed 
     } 
     else { 
      alert(itemFullPath + ' is an unknown object.'); // this alert is always shown 
     } 
    } 
} 

난 항상. "알 수없는 대상이다"라고 경고 상자를 얻을 :

이것은 내가 지금까지있는 것입니다. 그것은 isFile 및 isDirectory가 제대로 작동하지 않거나 뭔가 놓친 것 같습니까? 다른 사람도 같은 문제가 있습니까?

어떤 조언을 주셔서 감사합니다!

답변

1

다음 작업을해야합니다 :

var isDirectory = function(f){ 
    return f.exists() && f.getDirectoryListing() != null; 
} 

var isFile = function(f){ 
    return f.exists() && f.getDirectoryListing() == null; 
}