0

私は appcelarator titanium を使用して iPad アプリに取り組んでおり、ディレクトリの内容を繰り返し処理し、含まれているアイテムの種類 (ファイルかディレクトリか) を判断する必要があります。

これは私がこれまでに持っているものです:

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 が正しく動作していないようです。他の誰かが同じ問題を抱えていましたか?

アドバイスをありがとう!

4

1 に答える 1

1

以下が機能するはずです。

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

var isFile = function(f){
    return f.exists() && f.getDirectoryListing() == null;
}
于 2011-02-15T19:27:52.010 に答える