-1

Possible Duplicate:
How to get the file size given a path?

I am trying to find the size of a MP3 file on iPhone programmatically. (THIS FILE IS LOADED FROM ITUNES TO IPHONE AND THIS FILE IS NOT WITHIN APP DIRECTORY)

Unfortunately, I haven't been able to successfully to do that.

What classes or APIs should I use, please let me know.

Community
  • 1
  • 1

3 Answers3

2

The fact that it is an mp3 file does not matter. You just treat it as a normal file.
Look at the method attributesOfItemAtPath:error: of NSFileManager, and at the method fileSize of NSDictionary, it should give you what you need.

Guillaume
  • 21,685
  • 6
  • 63
  • 95
  • Thanks for the quick reply. Sorry, I will edit my question. Mp3 in question is loaded from itunes to iphone and is not within application directory. – Optimuus Prime Oct 11 '12 at 14:23
1

try this

unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:YourFilePath error:nil] fileSize];
Ayaz
  • 1,398
  • 15
  • 29
  • Thanks for the quick reply. Sorry, I will edit my question. Mp3 in question is loaded from itunes to iphone and is not within application directory. – Optimuus Prime Oct 11 '12 at 14:26
1

If the file is not within directory, app directory, yo do not have access to file, therefore are unable to perform any operation to calculate the size. This is due to iOS sandbox behavior.

J2theC
  • 4,412
  • 1
  • 12
  • 14