Approved: Fortect
I am trying to delete a file from the document directory, but it tells me that the file does not exist! Here are some more encodings:
let zipFiles = documentSTRINGS.filter $ 0.hasSuffix ("zip")........makeprint (zip files)try FileManager.default.removeItem (atPath: zipFiles.first!)catchprint (error)
prints out zipFiles [“file: ///private/var/mobile/Containers/Data/Application/XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/Documents/Accoltus.zip”]. So I fully understand the file, but it exists, it throws the following error:
Error Domain = NSCocoaErrorDomain Code = 4 “Accoltus.zip could not be deleted.” UserInfo = NSFilePath = file: /
Remove
Approved: Fortect
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
), NSUnderlyingError = 0x1c445d730 Error Domain = NSPOSIXErrorDomain Code = 2 “No such list or directory”
C ‘ it does not make sense. Does anyone know why this is happening?
I am trying to delete a file from the document directory, but it tells me that the file does not exist! B t my code:
let zipFiles equal documentSTRINGS.filter $ 0.hasSuffix ("zip")........makeprint (zip files)try FileManager.default.removeItem (atPath: zipFiles.first!)catchprint (error)
zipFiles prints out [“file: ///private/var/mobile/Containers/Data/Application/XXXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/Documents/Accoltus.zip”]. So, I know the file exists, but the following error occurred while printing:
This doesn’t make much sense. Does anyone know why this is happening?
Answer Accepted
Answers
No, your wide range of zip files consists of a URL string (it has a “file:” pattern at the beginning), so this is not the path to upload.
Whatever your documentSTRINGS creates a table, it prints the wrong thing in that table.
PS In general, don’t use the path based on the “removeItem (atPath :)” apis. B Instead, use URL-based APIs such as removeItem (at :).
Ok, I’ll go to the url. Why should I avoid personal chains out of curiosity?
This is how I get these documentSTRINGS:
let docDir = try! FileManager.default.url (for: .documentDirectory, at: .userDomainMask, good for: create: nil, false)let DocuURLS an equal try! FileManager.default.contentsOfDirectory (in: docDir includingPropertiesForKeys: nil)for urls in document urls leave urls to string = .relativeString DocuSTRINGS .append (string)
I have successfully used strings in multiple scopes to separate different file types.
Path strings cause problems for two reasons. First, the boot system uses a fixed character encoding, which can make using Unicode strings a little dangerous because you need to always be sure if your string is “fileSystemEncoding” or not. In addition, persistent permissions on the sandbox state are only associated with non-web addresses and paths, which may affect some applications. In addition, URLs could theoretically find files in more diverse locations, including the Internet, or use a broader alternative to access schemes.
For these reasons, it is currently recommended to use URLs in preparation paths for.
What Quincy Morris said, though …
URLs may contain other information that sweatcan significantly improve performance. For example, if you specify a site with
contentsOfDirectory (at: IncludePropertiesForKeys: options :)
, you can key the property phrase that interests you. Enumeration code can do enumerationand hides the value type property in each returned URL. Later when you make a profit on the property
resourceValues (forKeys :)
, it is provided by the cache instead of accessing the system manual files. This is important for drunk driving with volumes that have the correct latency for a long time, especially for network volumes on macOS, because you can list a directory and get all the values of interest along the way. Even with urban volumes, the latency is very low, but it still performs much better.
Share the fun and
–
Quinn “Eskimo!”
Apple Developer Relations, Developer Support, Core OS / Hardware
let myEmail = "eskimo" + "1" + "@ apple .com "
Speed up your computer's performance now with this simple download.
You are using FileManager to work with files with directories on iOS. It is a Swift API that helps you read and write articles in a variety of data and file formats. Change to directories that your operating system application has access to. Work with the Swift datatype and others.
The FileManager class provides a convenient way to identify a shared file manager object that is suitable for most types of file manipulation. The file manager object is often your primary way of interacting with your current file system. They use it to find, create, copy and move files as well as directories.
An object representing the location of the biography that is the bridge to the URL; Use NSURL when you need test semantics or Foundation-specific behavior.