简体   繁体   English

是否可以以编程方式从android上的照片/视频目录中删除所有文件?

[英]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.现在有了目录的路径,您可以简单地File(pathToDirectory).list().forEach{ it.delete() }根据您的需要自定义行为。 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为此,有字段isFileisDirectory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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