Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDocumentDirectory remove folder

I have created a folder inside documents directory using :

fileManager.createDirectory(atPath:ziPFolderPath,withIntermediateDirectories: false, attributes: nil)  

In this folder I have placed few files.
Later in the app, I want to delete not just the files inside the above folder, but also the folder.
FileManager supports removeItem function but I am wondering if it removes the folder as well.

like image 560
Nitish Avatar asked May 19 '17 10:05

Nitish


People also ask

How do I remove a folder from a folder?

Open My Computer or Windows Explorer. We recommend you make sure the directory or folder is empty before proceeding, unless you intend to delete everything in it. Locate the file or folder you want to delete and right-click it. Choose the Delete option from the pop-up menu.

How do I delete a folder in Golang?

In Go language, you are allowed to remove all the directories and files from a directory or folder with the help of RemoveAll() function. This function removes all the directories and files from the path you will pass to this function.

How do I delete a folder in Uipath?

Create a new variable folderExists of type Boolean and place it in Output -> Exists. The Path Exists activity returns a boolean response based on the folder existence. Add an If condition to check if folder exists. If it exists, Delete the folder using Delete activity by passing the folderPath.

How do I delete a Jupyter notebook folder?

Deleting a File or Folder To delete a file or folder from Jupyter Notebook, select the file or folder in the Files list and click the Delete button. NOTE: After the file or folder is deleted, click the Refresh button in the upper right corner to refresh the Jupyter page and clear the cache.


1 Answers

Yes it will delete folder also.

From the documentation of: - removeItem(at:)

Removes the file or directory at the specified URL.

From the documentation of: - removeItem(atPath:)

Removes the file or directory at the specified path.

Edit: You can call it like this way.

try? FileManager.default.removeItem(at: URL(fileURLWithPath: ziPFolderPath))
//OR
try? FileManager.default.removeItem(atPath: ziPFolderPath)
like image 133
Nirav D Avatar answered Oct 25 '22 13:10

Nirav D