Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / misc / RenameFilesMacro.groovy @ 2376

History | View | Annotate | Download (1.2 kB)

1
// STANDARD DECLARATIONS
2
package org.txm.macro.misc
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcp.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
// Open the parameters input dialog box
26
if (!ParametersDialog.open(this)) return;
27

    
28
// END OF PARAMETERS
29

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