Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / macroproto / RenameFilesMacro.groovy @ 187

History | View | Annotate | Download (1.2 kB)

1 187 sjacqu01
// STANDARD DECLARATIONS
2 187 sjacqu01
package org.txm.macroproto
3 187 sjacqu01
4 187 sjacqu01
import org.kohsuke.args4j.*
5 187 sjacqu01
import groovy.transform.Field
6 187 sjacqu01
import org.txm.rcpapplication.swt.widget.parameters.*
7 187 sjacqu01
8 187 sjacqu01
// BEGINNING OF PARAMETERS
9 187 sjacqu01
10 187 sjacqu01
@Field @Option(name="inputDirectory", usage="TXT directory", widget="Folder", required=false, def="txt")
11 187 sjacqu01
File inputDirectory;
12 187 sjacqu01
13 187 sjacqu01
// **change this parameter**
14 187 sjacqu01
@Field @Option(name="extension", usage="Regexp de l'extension des fichiers à modifier", widget="String", required=true, def='\\.txt')
15 187 sjacqu01
def extension = "\\.trs"
16 187 sjacqu01
17 187 sjacqu01
// **change this parameter**
18 187 sjacqu01
@Field @Option(name="find", usage="Expression régulière", widget="String", required=true, def='')
19 187 sjacqu01
def find = "Bobine"
20 187 sjacqu01
21 187 sjacqu01
// **change this parameter**
22 187 sjacqu01
@Field @Option(name="replaceWith", usage="Chaîne de remplacement", widget="String", required=false, def='\'')
23 187 sjacqu01
def replaceWith = ""
24 187 sjacqu01
25 187 sjacqu01
26 187 sjacqu01
// Open the parameters input dialog box
27 187 sjacqu01
if (!ParametersDialog.open(this)) return;
28 187 sjacqu01
29 187 sjacqu01
// END OF PARAMETERS
30 187 sjacqu01
31 187 sjacqu01
println "In $inputDirectory..."
32 187 sjacqu01
inputDirectory.eachFileMatch(~/.*$extension/) { file ->               // for each file matching extension
33 187 sjacqu01
                println " renaming: "+file.getName()
34 187 sjacqu01
                String name = file.getName()
35 187 sjacqu01
                name = name.replaceAll(find, replaceWith)
36 187 sjacqu01
                file.renameTo(new File(file.getParentFile(), name))
37 187 sjacqu01
        }