SHARE
TWEET

Clear Volatile and Backup Files

KosIvantsov Sep 12th, 2016 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* :name=Clear Volatile and Backup Files :description=
  2.  * @author  Kos Ivantsov
  3.  * @date    2016-09-12
  4.  * @version 0.1
  5.  */
  6.  
  7. import javax.swing.JOptionPane
  8. import static javax.swing.JOptionPane.*
  9. import static org.omegat.gui.main.ProjectUICommands.projectReload
  10.  
  11. title = "Delete files"
  12. String.metaClass.confirm = { ->
  13.         showConfirmDialog null, delegate, title, YES_NO_OPTION
  14. }
  15. String.metaClass.alert = { ->
  16.         showMessageDialog null, delegate, title, INFORMATION_MESSAGE
  17.         false
  18. }
  19.  
  20. prop = project.projectProperties
  21. if ( ! prop ) {
  22.     message = "Please try again after you open a project."
  23.     console.clear()
  24.     console.println(message)
  25.     message.alert()
  26.     return
  27. }
  28. dir = delTrg = {
  29.     it.eachDir(dir)
  30.     it.eachFile{ it.delete() }
  31. }
  32. omtfolder = (prop.getProjectRoot() + "omegat")
  33. rootfolder = (prop.getProjectRoot())
  34. projname = new File(rootfolder).getName()
  35. message = "The contents of target folder\n\
  36. [${prop.getTargetRoot()}];\n\
  37. all the project's memory backup files\n\
  38. [${prop.getProjectRoot()}omegat${File.separator}project_save.tmx.*.bak];\n\
  39. and all the export memory files\n\
  40. [${prop.getProjectRoot()}$projname${File.separator}$projname-*.tmx]\n\
  41. will be deleted. Proceed?"
  42. if ( message.confirm() == 0 ) {
  43.     delTrg new File(prop.getTargetRoot())
  44.     for(File f: new File(omtfolder).listFiles())
  45.         if(f.getName().startsWith("project_save.tmx") && f.getName().endsWith(".bak"))
  46.          f.delete()
  47.     for(File f: new File(rootfolder).listFiles())
  48.         if(f.getName().startsWith(projname) && f.getName().endsWith(".tmx"))
  49.          f.delete()
  50. }else{
  51.     console.println("Nothing deleted")
  52.     return
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top