Domanda

Ho questo pezzo di codice, che copia un file plist nella directory ApplicationSupport nella cartella utenti.

NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kAutonumberPlist];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);

    NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:kAutonumberPlist];
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath:dataPath]) {
        [fileManager copyItemAtPath:resourcePath toPath:dataPath error:nil];
    }

Come faccio a Ca modificarlo in modo che invece di copiare il file in ~ utente / Libreria / ApplicationSupport, copierà in ~ utente / Libreria / ApplicationSupport / AnotherFolder. Il "AnotherFolder" esiste già per la via.

Grazie!

È stato utile?

Soluzione

Si sta già utilizzando stringByAppendingPathComponent - si potrebbe utilizzare di nuovo

.

Ad esempio:

NSString *dataPath = [[[paths objectAtIndex:0] 
                        stringByAppendingPathComponent: @"AnotherFolder"]
                        stringByAppendingPathComponent: kAutonumberPlist];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top