一张图片用一个文件夹装,比如说有100张图片,就自动创建100个文件夹,每个文件夹装一张图片,这功能要怎么实现?
1条回答
- Jerome_Song 2013-12-10 13:01关注
java代码可以吗,就这么个逻辑 shell或python应该更简单
public static void main(String[] args) { File file = new java.io.File("/home/jerome/Pictures"); file.getAbsoluteFile(); String[] files = file.list(); for (String string : files) { System.out.println(string); File dir = new File(file.getAbsolutePath() + "/" + string.substring(0, string.lastIndexOf("."))); dir.mkdir(); copyFile(file+"/"+string, dir.getAbsolutePath()+"/"+string); delFile(file+"/"+string); } } public static void delFile(String filePathAndName) { try { String filePath = filePathAndName; filePath = filePath.toString(); java.io.File myDelFile = new java.io.File(filePath); myDelFile.delete(); } catch (Exception e) { e.printStackTrace(); } } public static void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(oldPath); FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; while ( (byteread = inStream.read(buffer)) != -1) { bytesum += byteread; fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { e.printStackTrace(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?