Created
May 11, 2015 20:43
-
-
Save rmorenobello/bbe31f254e91ed76e7ea to your computer and use it in GitHub Desktop.
Recorrer directorios, archivos y copiarlos con AntBuilder.copy()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://omarello.com/2010/09/groovy-to-the-rescue/ | |
static void moveDocumentationToMe(pathToFolder, groupId) { | |
// move everything to my desktop, of course i could have passed as an argument, | |
// but i don't really care for now | |
FileSystemView filesys = FileSystemView.getFileSystemView() | |
def destinationDir = filesys.getHomeDirectory().getCanonicalPath() | |
//paranoia <img src="http://omarello.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> | |
if (!destinationDir.endsWith(File.separator)) | |
destinationDir += File.separator | |
destinationDir += "Results" | |
//create the directory if it doesn't exist yet | |
def destDirFile = new File(destinationDir); | |
if (!destDirFile.exists()) | |
destDirFile.mkdir(); | |
//define a new AntBuilder in order to use | |
//the copy task to copy the files | |
def antBuilder = new AntBuilder() | |
File file = new File(pathToFolder) | |
for (f in file.listFiles()) { | |
// the path can contain many folders (don't ask why) | |
// The ones I want have the Group ID somewhere in the middle | |
// of the file name (thank god the naming convention is consistent) | |
if (f.name ==~ ".*${groupId}.*") { | |
//i need to get all files in this directory | |
def groupFolder = new File(pathToFolder + File.separator + f.name) | |
//and put them in their own direcoty in my destinationDir | |
def destSubDir = new File(destinationDir + File.separator + f.name) | |
if (groupFolder.listFiles()) { | |
//create the directory if it doesn't exist | |
if (!destSubDir.exists()) | |
destSubDir.mkdir(); | |
def targetPath | |
for (toMove in groupFolder.listFiles()) { | |
targetPath = destSubDir.getCanonicalPath() + File.separator + toMove.name | |
antBuilder.copy(file: "${toMove.getCanonicalPath()}", tofile: "${targetPath}") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment