Objective c 目标c-将文件复制到现有目录中
如何将文件从DIR1复制到DIR2,而不复制整个目录 我正在尝试将文件复制到包含其他文件的文件夹中,因此我不想创建新文件夹。以下代码的作用是:Objective c 目标c-将文件复制到现有目录中,objective-c,copy,nsfilemanager,Objective C,Copy,Nsfilemanager,如何将文件从DIR1复制到DIR2,而不复制整个目录 我正在尝试将文件复制到包含其他文件的文件夹中,因此我不想创建新文件夹。以下代码的作用是: [[NSFileManager defaultManager] copyItemAtPath:sourceDir toPath:destDir error:&err]; 获取文件夹中的所有内容 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NS
[[NSFileManager defaultManager] copyItemAtPath:sourceDir toPath:destDir error:&err];
获取文件夹中的所有内容
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileList = [[NSFileManager defaultManager] directoryContentsAtPath:documentsDirectory];
枚举文件列表并复制它们
[fileList enumerateObjectsUsingBlock:^(NSString *string, NSUInteger index, BOOL *stop) {
[[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error];
}];
获取文件夹中的所有内容
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileList = [[NSFileManager defaultManager] directoryContentsAtPath:documentsDirectory];
枚举文件列表并复制它们
[fileList enumerateObjectsUsingBlock:^(NSString *string, NSUInteger index, BOOL *stop) {
[[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error];
}];
获取文件夹中的所有内容
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileList = [[NSFileManager defaultManager] directoryContentsAtPath:documentsDirectory];
枚举文件列表并复制它们
[fileList enumerateObjectsUsingBlock:^(NSString *string, NSUInteger index, BOOL *stop) {
[[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error];
}];
获取文件夹中的所有内容
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileList = [[NSFileManager defaultManager] directoryContentsAtPath:documentsDirectory];
枚举文件列表并复制它们
[fileList enumerateObjectsUsingBlock:^(NSString *string, NSUInteger index, BOOL *stop) {
[[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error];
}];
我就是这样做的:
NSArray *sourceFiles = [fileManager contentsOfDirectoryAtPath:sourceDir error:NULL];
NSError *copyError = nil;
for (NSString *currentFile in sourceFiles)
{
BOOL isDirectory = NO;
NSString* fullFilePath = [NSString stringWithFormat:@"%@/%@",sourceDir,currentFile];
if ([fileManager fileExistsAtPath:fullFilePath isDirectory:&isDirectory] && !isDirectory)
{
if (![fileManager copyItemAtPath:[sourceDir stringByAppendingPathComponent:currentFile] toPath:[destDir stringByAppendingPathComponent:currentFile] error:©Error])
{
NSLog(@"Error Copying: %@", [copyError description]);
}
}
}
我就是这样做的:
NSArray *sourceFiles = [fileManager contentsOfDirectoryAtPath:sourceDir error:NULL];
NSError *copyError = nil;
for (NSString *currentFile in sourceFiles)
{
BOOL isDirectory = NO;
NSString* fullFilePath = [NSString stringWithFormat:@"%@/%@",sourceDir,currentFile];
if ([fileManager fileExistsAtPath:fullFilePath isDirectory:&isDirectory] && !isDirectory)
{
if (![fileManager copyItemAtPath:[sourceDir stringByAppendingPathComponent:currentFile] toPath:[destDir stringByAppendingPathComponent:currentFile] error:©Error])
{
NSLog(@"Error Copying: %@", [copyError description]);
}
}
}
我就是这样做的:
NSArray *sourceFiles = [fileManager contentsOfDirectoryAtPath:sourceDir error:NULL];
NSError *copyError = nil;
for (NSString *currentFile in sourceFiles)
{
BOOL isDirectory = NO;
NSString* fullFilePath = [NSString stringWithFormat:@"%@/%@",sourceDir,currentFile];
if ([fileManager fileExistsAtPath:fullFilePath isDirectory:&isDirectory] && !isDirectory)
{
if (![fileManager copyItemAtPath:[sourceDir stringByAppendingPathComponent:currentFile] toPath:[destDir stringByAppendingPathComponent:currentFile] error:©Error])
{
NSLog(@"Error Copying: %@", [copyError description]);
}
}
}
我就是这样做的:
NSArray *sourceFiles = [fileManager contentsOfDirectoryAtPath:sourceDir error:NULL];
NSError *copyError = nil;
for (NSString *currentFile in sourceFiles)
{
BOOL isDirectory = NO;
NSString* fullFilePath = [NSString stringWithFormat:@"%@/%@",sourceDir,currentFile];
if ([fileManager fileExistsAtPath:fullFilePath isDirectory:&isDirectory] && !isDirectory)
{
if (![fileManager copyItemAtPath:[sourceDir stringByAppendingPathComponent:currentFile] toPath:[destDir stringByAppendingPathComponent:currentFile] error:©Error])
{
NSLog(@"Error Copying: %@", [copyError description]);
}
}
}
directoryContentsAtPath:
已弃用。改用contentsOfDirectoryAtPath:error:
。directoryContentsAtPath:
不推荐使用。改用contentsOfDirectoryAtPath:error:
。directoryContentsAtPath:
不推荐使用。改用contentsOfDirectoryAtPath:error:
。directoryContentsAtPath:
不推荐使用。改为使用目录路径:错误:的内容。