How can I download an entire directory? - iphone

Is it possible in Objective-C to download an entire directory to the documents directory so I would end up with a subfolder in the documents directory with a name of my choosing? Then, is it possible to delete that directory and all its contents without looping through all the files? Many thanks in advance.

The short answer is 'Yes, its possible' given that the directory and files in question are not larger than the available space on the device. If you are talking about some text files or some images then I don't see a problem.
Not so sure about deleting all the contents without first getting a pointer to the files but that shouldn't take long in any case.
Were you looking for specific code examples as well?
There is a similar question, and answer [here].1

You cannot download entire folders over the internet, you would have to list the files and download them one by one.
You can use NSFileManager to create, read and remove files in your apps folder. You can delete a complete folder without having to loop through all the items in the folder.
(BOOL)removeItemAtPath:(NSString )path error:(NSError *)error;
Have a look at the NSFileManager documentation:
NSFileManager documentation
Keep in mind that whenever you go outside the "sandbox" of your app, your app will be rejected by apple. So keep those files within your app's bundle.

Related

How can I exclude a file from iTunes file sharing?

iTunes file sharing works by exposing all the files in /Documents
But I would want to explicitly exclude certain files. Is this possible?
UPDATED:
Specifically, one of my ad network SDK is storing a mraid.js in Documents.
If you don't want a file shared, don't store it in the Documents folder. Use the Application Support folder for example.
Another option is that iTunes won't show any files or folders from the Documents folder that start with a dot. You could rename the files you don't want to share with a dot or put them in a subfolder whose name begins with a dot.
Try looking at This Question. Also, depending on what you are storing, you can try using the NSUserDefaults instead.
There is no way to exclude files from File Sharing.
The files you need to share should be put under Documents directory and the files which you don't want to share should be kept in other directories. It'll solve the issue.

Whats the difference between saving content at document directory or temp folder?

I want to save multipel photos in my application, so that application run in background.
So what is the main difference between saving photos in doc dir or temp path.
And suggest me which is best way to save photos
Document Dir
Temp Folder
NSUserDefaults
Thanks in advance
Here is a reference: File System Programming Guide.
Temp folder:
Use this directory to write temporary files that do not need to
persist between launches of your app. Your app should remove files
from this directory when it determines they are no longer needed. (The
system may also purge lingering files from this directory when your
app is not running.)
Documents folder:
Use this directory to store critical user documents and app data
files. Critical data is any data that cannot be recreated by your app,
such as user-generated content.
Usually, I put files in temporary folder only when I cache something and I don't care if these files will be deleted. If I want to be sure these files should live long life, I put them to documents folder.
The main difference is the path: <sandbox>/Documents or <sandbox>/tmp.
Some more differences:
The Documents directory can be accessed via iTunes if your app has file sharing enabled.
The contents of the tmp directory is volatile, the OS is free to purge it in order to save space.
About NSUserDefaults: that's something completely different, it's a mechanism which stores app-specific configuration data in property lists, I can't imagine how and/or why you would use it for storing images.

UIFileSharingEnabled use folders

I want to allow users add files to the application document folder, so I used the iTunes file sharing. The problem is they can only add single files with a flat structure. I want to drag and drop whole folder (even with sub folders) and keep the structure.
Questions I have:
is it possible with iTunes file sharing?
if not, is there an open source project that helps me with writing a pc side app that talks to the iPhone side app and pushes the files into it?
No you can't add Folder's/sub folders, iTunes will show just the files in the documents root. I think the only way to do that is to add it as zip file and you extract it in your app.
Maybe CocoaHTTPServer will help you.

Iterating through all the subfolders of a folder in iphone

IS there any efficient way to iterate through all the subfolders I've created inside my iphone App's Documents folder ? (Of course, without knowing their names or how many there are...)
Thanks...
Guy.
See the documentation for -[NSFileManager enumeratorAtPath:]. It contains sample code that does what you want.

How to create a list of directory and import images to them

As you knew, a iphone app has 4 directories: Application folder, Document, Library, tmp.
When app is installed in the first time, I want to:
Create a list of directories in Document folder
Import a list of images to each that directories.
I searched and found the way to create directory in Document folder by code.
[[NSFileManager defaultManager] createDirectoryAtPath:newDirectoryPath attributes: nil];
But following that way, user must create folder and import images by themself after installing app. I want my app do that.
Anybody know how to do it, please help me.
Thanks in advance!
Tien
I found out a solution for my situation. I mean that I want to create a list directory when app run at the first time. But now, I don't need to do it, I just need to add images to my resources folder and find the way to use them in interface builder.
Thanks you all for your attention and sorry for any inconvenient.
Regards,
Tien