2011-01-07 9 views
0

私はappcelarator titaniumを使用しているiPadアプリで作業しており、ディレクトリのコンテンツを繰り返し処理し、ファイルまたはディレクトリであるかどうかにかかわらず、アイテムの種類を判断する必要があります。Appelerator 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; 
} 
関連する問題