gpt4 book ai didi

iphone - iOS : cannot delete file

转载 作者:行者123 更新时间:2023-11-29 11:09:33 28 4
gpt4 key购买 nike

我是 iOS 新手。我有一个问题。

我记录文件的路径,并在 Finder 中验证它。但是 fileExistsAtPath: 返回 NO,这就是我无法删除它的原因。

我需要帮助!!

代码如下:

+ (void)removeImage:(NSString*)imgName {
MyLog(@"%@", [Tool getFileFullPath:imgName]);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL fileExists = [fileManager fileExistsAtPath:(NSString *)[Tool getFileFullPath:imgName]];
NSLog(@"Path to file: %@", [Tool getFileFullPath:imgName]);
NSLog(@"File exists: %d", fileExists);
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:[Tool getFileFullPath:imgName]]);
if (fileExists)
{
BOOL success = [fileManager removeItemAtPath:[Tool getFileFullPath:imgName] error:&error];
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
}

}

文件路径:/Users/vibolteav/Library/Application Support/iPhone Simulator/5.1/Applications/FD57CA70-14E4-442D-9CA5-DE7A7AD56A93/Documents/img/2053871632

文件存在:0

可删除文件位于路径:1

最佳答案

要从文档目录中删除文件,请使用以下代码:

 -(void)removeOneImage:(NSString*)fileName
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:fileName];
NSLog(@"%@",fullPath);
[fileManager removeItemAtPath: fullPath error:NULL];

关于iphone - iOS : cannot delete file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12136404/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com