1-500,501-1000,1001-1500,每500个文件一个文件夹的算法
for(List<TCComponentDataset> allDataSetList : allDataSetsList) { for(int index=0;index<allDataSetList.size();index++) { int number = index + 1; waitingDialog.getContent().setText("共有"+dataSetSize+"个数据集需要导出,正在导出第"+number+"个数据集..."); TCComponentDataset dataSetIndex = allDataSetList.get(index); String dataSetName = dataSetIndex.getProperty("object_name"); int num = index / 500; String folderName = (1+(num*500)) + "-" + ((num+1) * 500); String folderPath = path + "\\"+folderName; File folderFile = new File(folderPath); if(!folderFile.exists()) { folderFile.mkdir(); } String newFileName = folderPath + "\\" + dataSetName; File destFile = new File(newFileName); File srcFile = HFDatasetUtil.getInstance().getFile(dataSetIndex,errorSb); if(srcFile != null) { FileUtils.copyFile(srcFile, destFile); } } }
核心代码:
for(int index=0;index<allDataSetList.size();index++) { int num = index / 500; String folderName = (1+(num*500)) + "-" + ((num+1) * 500); String folderPath = path + "\\"+folderName; if(!folderFile.exists()) { folderFile.mkdir(); } }