Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / swb / RenameFilesInDirectoryByRegExp.groovy @ 1000

History | View | Annotate | Download (1.4 kB)

1
package org.txm.scripts.sw
2
// Copyright © - ENS de Lyon - http://textometrie.ens-lyon.fr
3
//
4
// This file is part of the TXM platform.
5
//
6
// The TXM platform is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
10
//
11
// The TXM platform is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
18
//
19
// $LastChangedDate: 2012-02-01 17:58:45 +0100 (mer., 01 févr. 2012) $
20
// $LastChangedRevision: 2122 $
21
// $LastChangedBy: mdecorde $
22
//
23
import org.txm.scripts.importer.*
24

    
25
// PARAMETERS
26

    
27
File dir = new File("/home/mdecorde/TEMP/atelier")
28
String searchRegexp = "(.+).txt"
29
String replaceRegexp = 't$1.txt' // WARNING: Use simple quotes only
30

    
31
// END OF PARAMETERS
32

    
33
// main body
34
dir.eachFileMatch(~/.*.txt/){ file -> // for each file with extension "txt"
35
        String filename = file.getName()
36
        filename = filename.replaceAll(searchRegexp, replaceRegexp)
37
        println "Rename file '$file' to '$filename'"
38
        file.renameTo(new File(file.getParent(), filename))
39
}