0

i want to copy all type of file that place in document directory to a another directory in ios,

if ([fileManager fileExistsAtPath:txtPath] == YES) {
    [fileManager removeItemAtPath:txtPath error:&error];
}

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"txtFile" ofType:@"txt"];
[fileManager copyItemAtPath:resourcePath toPath:txtPath error:&error];

I M Using This Code But it is only help in specific one type of file.

Hardik Vyas
  • 1,973
  • 1
  • 20
  • 43

2 Answers2

1

Finally I got My Answer After Doing Some Changes and finding from the other reference and i found this code that running perfect for me

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray1 = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:dataPath  error:nil];
Hardik Vyas
  • 1,973
  • 1
  • 20
  • 43
0

Check the below code to get all type of files from a directory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSArray *filePaths = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];

Ari Haran
  • 61
  • 1
  • 2
  • 5