简体   繁体   中英

is it possible to delete all files from photo/video directory on android programmatically?

I'm developing an app that has the functionality to upload all video and photo files to an external server, and I would like to offer the user the possibility to empty their photo and video directory...soon there is some easy way to do that? erasing everything at once

I assume your app already has a way to get access to the path to the directory you want to clear, and a permission to access the storage. Now having the path to the directory you could simply File(pathToDirectory).list().forEach{ it.delete() } Customize the behavior based on your needs. For example, you could recursively call the function containing the code above to clear a directory and all included subdirectories, or you could leave folders untouched and just delete files. For that, there are fields isFile and isDirectory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM