List of utility methods to do Rename File
boolean | renameFileOnWindows(File oldFile, File newFile) rename File On Windows String sCurrentLine = ""; try { BufferedReader bufReader = new BufferedReader(new FileReader(oldFile.getAbsoluteFile())); BufferedWriter bufWriter = new BufferedWriter(new FileWriter(newFile.getAbsoluteFile())); while ((sCurrentLine = bufReader.readLine()) != null) { bufWriter.write(sCurrentLine); bufWriter.newLine(); bufReader.close(); bufWriter.close(); oldFile.delete(); return true; } catch (Exception e) { return false; |
void | renameFiles(File fileDirectory, String regex, String replacement) rename Files for (File file : fileDirectory.listFiles()) { File newFile = new File(file.getAbsolutePath().replaceFirst(regex, replacement)); file.renameTo(newFile); |
File[] | renameFiles(String rootDir, String sourcePostfix, String destPostfix) Recursive rename the child file with given extension to another extension of root directory.Return true when rename successfully,otherwise return false
File[] renamedFailedFiles = new File[0]; List<File> fileList = new ArrayList<File>(); File rootFile = new File(rootDir); File[] subFiles = rootFile.listFiles(); for (File file : subFiles) { if (file.isDirectory()) { File[] tempRenamedFailedFiles = renameFiles(file.getPath(), sourcePostfix, destPostfix); for (File tempFile : tempRenamedFailedFiles) { ... |
void | renameFolder(String destinationFolderPath, String zipFileName, String prefix) rename Folder File folder = new File(destinationFolderPath + File.separator + zipFileName); File managerFolder = new File(destinationFolderPath + File.separator + prefix + zipFileName); if (folder.exists()) { folder.renameTo(managerFolder); } else { System.out.println(zipFileName + " Folder not found..!!"); |
boolean | renameLocal(String oldPath, String newPath) rename Local System.out.println("Renaming local item " + oldPath + " to " + newPath); File oldFile = new File(oldPath); File newFile = new File(newPath); return (oldFile.renameTo(newFile)); |
void | renameOldFile(final String fileName) rename Old File final File file = new File(fileName); if (file.exists()) { final File oldFile = new File(fileName + ".old"); if (oldFile.exists()) { oldFile.delete(); file.renameTo(oldFile); |
void | renameOverwrite(String oldname, String newname) Rename the file with oldname to newname. try { if (exists(oldname)) { delete(newname); File file = new File(oldname); file.renameTo(new File(newname)); } catch (Throwable e) { throw toIOException(e); ... |
File | renameSuffix(File f, String suffix) rename Suffix if (null == f || null == suffix || suffix.length() == 0) return f; return new File(renameSuffix(f.getAbsolutePath(), suffix)); |
void | renameTempDMLScript(String dmlScriptFile) Renames a temporary DML script file back to it's original name. File oldPath = new File(dmlScriptFile + "t"); File newPath = new File(dmlScriptFile); oldPath.renameTo(newPath); |
void | renameTo(File currentFile, String newName) Platform independent rename function try { File newFile = new File(newName); Files.move(currentFile, newFile); } catch (IOException e) { e.printStackTrace(); |