How to delete files of a directory but not the folders

后端 未结 6 2236
死守一世寂寞
死守一世寂寞 2021-01-15 12:48

I have create some code that deletes all the files in a folder, the issue is while this is great, I want to be able to delete all the files in a directory but leave the fold

6条回答
  •  旧时难觅i
    2021-01-15 13:14

    Why not just do

    if (!myFile.isDirectory()) myFile.delete();
    

    instead of

    myFile.delete();
    

    ?

提交回复
热议问题