iOS、Mac 创建文件夹是无视大小写的。
无意间发现的一个问题!!!
iOS 居然无法识别文件夹 a 和 A,认为是同一个!所以在同一目录下无法共存。
{
NSError* error = nil;
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingFormat:@"/output/a"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
}
if (error) {
NSLog(@"a %@", error.localizedDescription);
}
}
{
NSError* error = nil;
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingFormat:@"/output/A"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
}
if (error) {
NSLog(@"A %@", error.localizedDescription);
}
}
创建文件夹a 和 A,为啥A创建失败。
The file “A” couldn’t be saved in the folder “output”.
然后试试重名看看。
{
NSError* error = nil;
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingFormat:@"/output/a"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
}
if (error) {
NSLog(@"a %@", error.localizedDescription);
}
}
{
NSError* error = nil;
NSString* path0 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingFormat:@"/output/A"];
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingFormat:@"/output/AAA"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"AAA %@", error.localizedDescription);
if (error == nil) {
[[NSFileManager defaultManager] moveItemAtPath:path toPath:path0 error:&error];
NSLog(@"AA %@", error.localizedDescription);
}
}
}
AA “AAA” couldn’t be moved to “output” because an item with the same name already exists.
看到错误信息之后,得到的结论是题目。。。
Mac直接创建问题就可以试了。
创建路径,大小写没有区别,所以定义要谨慎!