Statistics
| Revision:

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

History | View | Annotate | Download (1.2 kB)

1
// STANDARD DECLARATIONS
2
package org.txm.macroproto
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7

    
8
// BEGINNING OF PARAMETERS
9

    
10
@Field @Option(name="inputDirectory", usage="TXT directory", widget="Folder", required=false, def="txt")
11
File inputDirectory;
12

    
13
// **change this parameter**
14
@Field @Option(name="extension", usage="Regexp de l'extension des fichiers à modifier", widget="String", required=true, def='\\.txt')
15
def extension = "\\.trs"
16

    
17
// **change this parameter**
18
@Field @Option(name="find", usage="Expression régulière", widget="String", required=true, def='')
19
def find = "Bobine"
20

    
21
// **change this parameter**
22
@Field @Option(name="replaceWith", usage="Chaîne de remplacement", widget="String", required=false, def='\'')
23
def replaceWith = ""
24

    
25

    
26
// Open the parameters input dialog box
27
if (!ParametersDialog.open(this)) return;
28

    
29
// END OF PARAMETERS
30

    
31
println "In $inputDirectory..."
32
inputDirectory.eachFileMatch(~/.*$extension/) { file ->               // for each file matching extension
33
                println " renaming: "+file.getName()
34
                String name = file.getName()
35
                name = name.replaceAll(find, replaceWith)
36
                file.renameTo(new File(file.getParentFile(), name))
37
        }