2

I would like to assign a variable instead of the string in my following code. First i am creating an array from comma separated list of directories. Next for each directory in the array, i want to create them, if they doesn't exist.

How do i assign the directory from the array rather than: @"templates/standard1/css" I have tried replacing it with s, but that didn't work out. I can NSlog the s, but it doesn't seem to create the directories.

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

NSString *theString = @"templates, templates/standard1, templates/standard1/css, themes, themes/plain, themes/plain/384";
NSArray *items = [theString componentsSeparatedByString:@","];
for (NSString *s in items) {
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"templates/standard1/css"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
        // Directory does not exist so create it
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:nil];
    }

}

Any help would be appreciated :)

2
  • WOW! How stupid was that? Thank you for pointing that out! :) Commented Jun 14, 2012 at 17:24
  • @trumpetlicks you should answer the question so you can get the credit. Commented Jun 14, 2012 at 18:05

1 Answer 1

3

I think the spaces are bothering your directories. You have each directory separated by ", " but are searching for "," (without a space). You can either take the spaces out of your theString, or use ", " as your separator, for using the string!!!

So either change

NSString *theString = @"templates, templates/standard1, templates/standard1/css, themes, themes/plain, themes/plain/384";

to this

NSString *theString = @"templates,templates/standard1,templates/standard1/css,themes,themes/plain,themes/plain/384";

Or Change this:

NSArray *items = [theString componentsSeparatedByString:@","];

to this:

NSArray *items = [theString componentsSeparatedByString:@", "];

BUT NOT BOTH!!!

Sign up to request clarification or add additional context in comments.

1 Comment

Glad I could help, Keep having fun :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.