Skip to content

Instantly share code, notes, and snippets.

@AvatarQing
Created December 7, 2014 04:27
Show Gist options
  • Save AvatarQing/974f716f051a92c705c7 to your computer and use it in GitHub Desktop.
Save AvatarQing/974f716f051a92c705c7 to your computer and use it in GitHub Desktop.
2048图片重命名
@echo off
groovy Renamer -i %1 -o %~dp0New%~n1
pause
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
def renameImages(def dirPath,def saveDirPath){
new File(saveDirPath).mkdirs()
def dirFile=new File(dirPath)
dirFile.listFiles().eachWithIndex {inFile,i->
String name=inFile.getName()
def number=Math.pow(2, i+1) as int
def outfileNameSuffix=name.substring(name.lastIndexOf(".")+1);
def outfileNamePreffix="cell_rectangle_"
def outfileName= "${outfileNamePreffix}${number}.${outfileNameSuffix}"
def outFilePath="${saveDirPath}${File.separator}${outfileName}"
def outFile=new File(outFilePath)
def is= inFile.newInputStream()
def os= outFile.newOutputStream()
byte[] buffer = new byte[256]
int byteread = 0
int bytesum = 0
int length;
while ( (byteread = is.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
os.write(buffer, 0, byteread);
}
is.close();
os.close();
println outFilePath
}
}
def cli = new CliBuilder()
cli.h( longOpt: 'help', required: false, 'Show usage information' )
cli.i( longOpt: 'inputdir', argName: 'input director path', required: true, args: 1, 'Original images directory path' )
cli.o( longOpt: 'outputdir', argName: 'output director path', required: true, args: 1, 'The output directory path' )
def opt = cli.parse(args)
if (!opt) {
return
}
if (opt.h) {
cli.usage()
return
}
if(opt.i && opt.o) {
renameImages(opt.i,opt.o)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment