0

I want to remove a file. For it, I have the url. Its url.absoluteString is:

file:///private/var/mobile/Containers/Shared/AppGroup/UUID/Library/Caches/someLocation/CexRlA-L:2258

The file exists because

FileManager.default.fileExists(atPath: url.path) == true

But doing

try FileManager.default.removeItem(at: url)

fails with error:

Failed to remove "CexRlA-L/2258"

FileManager changes the : in the filename (CexRlA-L:2258) to /. So CexRlA-L becomes treated as a folder and it of course does not exist.

I have not managed to reproduce locally, but it happens often to our users. Any pointers on what may be going on?

Thanks in advance.

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
  • You don't by any chance use [`displayName(atPath:)`](https://developer.apple.com/documentation/foundation/filemanager/1409751-displayname) ? *That* function would translate a colon to a slash. I am not aware that any other FileManager function does such a translation implicitly. – Martin R Jan 30 '20 at 13:57
  • Unfortunately, no. I do `let url = folderURL?.appendingPathComponent("CexRlA-L:2258")` and before I run `FileManager.default.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)`. folderURL is created by appending `Library`, `Caches` and `someLocation` to the shared file URL `FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com...")` – regina_fallangi Jan 30 '20 at 14:11
  • https://stackoverflow.com/a/24552028/8294374 – Enea Dume Jan 30 '20 at 14:25

0 Answers0