2012-03-30 23 views
0

私はサウンドファイルを録音したアプリがあります。必要なファイルや既存のファイルを他の賢明でない人にアップロードする必要があるかどうかを確認したい場合がありますこのファイルがiPhoneにあるかどうかを確認する方法

私は、このファイルの終了は、私はそれのような多くの

int i=0; 
    for (i=0; i<[types count]; i++) { 


    NSString*type=[types objectAtIndex:i]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 




    NSString * filePath = [NSString stringWithFormat:@"%@/Documents/%@_%@_%@_%@.wav", NSHomeDirectory(),theCellData.firstName,theCellData.lasttName,theCellData.patientId,type]; 




    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath]; 

    } 
+0

問題は何ですか?あなたはファイルが存在するかどうかをチェックしています。 –

+0

BOOLに何も表示されていない –

+0

そこにブレークポイントを入れてみましたか?またはNSLog(@ "%d"、fileExists)を入力します。 0なら1を返し、0なら1を返します。 –

答えて

0
int i=0; 
for (i=0; i<[types count]; i++) 
{ 
NSString*type=[types objectAtIndex:i]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [NSString stringWithFormat:@"%@/%@_%@_%@_%@.wav",documentsDirectory,theCellData.firstName,theCellData.lasttName,theCellData.patientId,type]; 
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath]; 
if (fileExists == 0) 
{ 
    NSLog(@"File is Not exists"); 
} 
else 
{ 
    NSLog(@"File exists"); 
} 
} 
+0

私はあなたのコードを受け入れていますが、私のコードを編集してコード内にそのパスを与えることができます –

+0

私はあなたの答えを更新しました.. – akk

+0

私のことを間違えて申し訳ありません。再び私は私の答えを更新...コードを取得... – akk

0

そうではないと呼ばれるべきであること、次に、[自己のアップロード]のようなメソッドを持っている場合は、その私が欲しい不可欠などのようにそこに値するタイプの配列を持っています上記の答えですが、完全性のために、あなたのコードは次のようになります。あなたの質問。 (あなたがココアをやや新しくしたと思います...)

NSString* documentsPath1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString* foofile = [documentsPath1 stringByAppendingFormat:@"/%@_%@_%@_%@.wav", theCellData.firstName, theCellData.lasttName, theCellData.patientId, type]; 
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath: foofile]; 
if (fileExists == NO) 
{ 
    NSLog(@"File does not exist"); 
} 
else 
{ 
    NSLog(@"File exists"); 
} 
関連する問題