2012-04-11 6 views
0

私は画像やテキストのようなユーザーデータを格納するAppを持っています。私はどのくらいのディスクスペースが私のアプリケーションで消費されているかを示したいと思います。これは可能ですか?Appによってプログラムで使用されるストレージの状態を取得するにはどうすればよいですか?

+0

あなたのデータはどこに保存されていますか?それはsqliteファイルかNSDocumentsDirectoryかNSFileManagerを使用しています – Charan

+0

3つすべてを使用しています。 –

答えて

1

私は3つすべてを知らないが、私は、ファイルマネージャを介して、ディレクトリ内のドキュメントのサイズを取得するために何かを行っている、これはあなたを助けるかもしれ、ここ

[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir]; 
     if (isDir) { 
      NSPipe *pipe = [NSPipe pipe]; 
      NSTask *t = [[[NSTask alloc] init] autorelease]; 
      [t setLaunchPath:@"/usr/bin/du"]; 
      [t setArguments:[NSArray arrayWithObjects:@"-k", @"-d", @"0", path, nil]]; 
      [t setStandardOutput:pipe]; 
      [t setStandardError:[NSPipe pipe]]; 

      [t launch]; 

      [t waitUntilExit]; 

      NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading] availableData] encoding:NSASCIIStringEncoding] autorelease]; 
      sizeString = [[sizeString componentsSeparatedByString:@" "] objectAtIndex:0]; 
      bytes = [sizeString longLongValue]*1024; 
     } 
     else { 
      bytes = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize]; 
     } 

バイトが戻りますコードがありますサイズ

関連する問題