确认是否删除文件夹/文件夹?
2012-04-09 18:02
204 查看
public void confirmDel(final String path ,final int folder){ AlertDialog.Builder ad1=new AlertDialog.Builder(FileManagerActivity.this); ad1.setTitle("删除文件夹?"); ad1.setPositiveButton("是", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int i) { // TODO Auto-generated method stub if (folder==1) { delFolder(path); } else { delFile(path); } } }); ad1.setNegativeButton("否",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int i) { } }); ad1.show();//显示对话框 } public boolean delFile(String path) { File file = new File(path); return file.delete(); //return true; } public void delFolder(String folderPath) { try { delAllFile(folderPath); //删除完里面所有内容 String filePath = folderPath; filePath = filePath.toString(); java.io.File myFilePath = new java.io.File(filePath); myFilePath.delete(); //删除空文件夹 } catch (Exception e) { System.out.println("删除文件夹操作出错"); e.printStackTrace(); } } /** * 删除文件夹里面的所有文件 * @param path String 文件夹路径 如 c:/fqf */ public void delAllFile(String path) { File file = new File(path); if (!file.exists()) { return; } if (!file.isDirectory()) { return; } String[] tempList = file.list(); File temp = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + tempList[i]); } else { temp = new File(path + File.separator + tempList[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delAllFile(path+"/"+ tempList[i]);//先删除文件夹里面的文件 delFolder(path+"/"+ tempList[i]);//再删除空文件夹 } }
相关文章推荐
- 确认是否删除文件夹/文件夹?
- c#实现在一个表中有一个Url字段,查每条记录是否在一个文件夹下.如在保留此记录,不在将这个记录删除
- 删除空文件夹报错:该项目不在F:\中,请确认该项目中的位置,然后重试。
- .net Button按钮提示 确认是否删除
- iOS文件和文件夹的创建,删除,移动, 拷贝,是否存在及简单数据类型的读写
- java判断文件夹是否存在某一文件 如果存在就删除功能
- C# 文件、文件夹操作语句(删除,创建,移动,检查是否存在)
- JavaScript js弹出确认消息框判断是否删除,删除前提示用户是否删除,点是删除,点否返回
- Win8系统删除文件或文件夹时未出现确认对话框解决方法
- 创建,删除文件或文件夹及判断其是否存在
- JS返回是否确认删除或者其他…
- C/C++ 判断文件夹是否存在以及创建、删除文件夹 windows以及linux通用
- 无法删除文件夹 出现:无法删除Cmcmcmcm:找不到指定文件。请确定指定的路径及文件名是否正确。
- MFC确认文件夹是否存在,以及创建文件夹
- c# winform 弹出确认消息框判断是否删除?
- 是否确认删除
- 删除前弹出对话框让用户确认是否删除.的对话框!
- JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤
- JavaScript删除确认代码,判断checkbox是否被选中代码
- 为Gridview的CommandField删除添加 "是否确认删除?"