ios - 删除文件名中带有空格的文件 ios
<p><p>我想删除文档目录的图像。该图像具有这种 <code>2016-06-08 12:24:55.897image.jpg</code> 类型的命名约定。</p>
<p>代码片段</p>
<pre><code>-(void) removeImageAtPath:(NSString *) filePath{
NSError *error;
NSFileManager *fileManager = ;
BOOL success = ;
if (success) {
NSLog(@"Image Successfully Deleted");
}
else{
NSLog(@"Could not delete file -:%@ ",);
}
}
</code></pre>
<p>错误代码
<code>NSCocoaErrorDomain 代码 = 4</code></p>
<p>我知道找不到文件时会出现错误。这是由于我使用的命名约定而发生的。
我不能改变约定。有什么办法仍然可以删除文件。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>此代码直接删除文件名</p>
<pre><code> - (void)removeImage:(NSString *)filename
{
NSFileManager *fileManager = ;
NSString *documentsPath = ;
NSString *filePath = ;
NSError *error;
BOOL success = ;
if (success) {
UIAlertView *removedSuccessFullyAlert = [ initWithTitle:@"Congratulations:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
;
}
else
{
NSLog(@"Could not delete file -:%@ ",);
}
}
</code></pre>
<p>其他明智的使用此代码</p>
<pre><code>NSError *error;
if ([ isDeletableFileAtPath:path]) {
BOOL success = [ removeItemAtPath:path error:&error];
if (!success) {
NSLog(@"Error removing file at path: %@", error.localizedDescription);
}
}
</code></pre>
<p>你能试试这个代码吗</p>
<pre><code>NSFileManager *fileManager = ;
NSError *error;
BOOL fileExists = ;
NSLog(@"Path to file: %@", path);
NSLog(@"File exists: %d", fileExists);
NSLog(@"Is deletable file at path: %d", );
if (fileExists)
{
BOOL success = ;
if (!success) NSLog(@"Error: %@", );
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 删除文件名中带有空格的文件 ios,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37695584/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37695584/
</a>
</p>
页:
[1]