Created
June 17, 2011 02:41
-
-
Save xnrghzjh/1030755 to your computer and use it in GitHub Desktop.
指定した拡張子のファイルを生成日のフォルダに移動(wsfから移植)
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
/** | |
課題 拡張子を取得する処理を簡略化、 | |
クロージャ内でクロージャが呼べない | |
なんか遅い | |
*/ | |
import javax.swing.* | |
// 移動対象 | |
def folderPath = "." | |
def filterList = ['jpg', 'bmp'] | |
// 拡張子判定 | |
def isTarget = { name -> | |
target = false | |
filterList.each() { | |
arg = name.split("\\.") | |
if (arg.length == 2) { | |
if (it.compareToIgnoreCase(arg[1]) == 0) | |
target = true | |
} | |
} | |
target | |
} | |
// 移動先のフォルダ名 | |
def getFolderName = { new Date(it).format('yyyyMMdd') } | |
// 実行 | |
count = 0 | |
new File(folderPath).listFiles().each { | |
if (it.isFile() && isTarget(it.name)){ | |
// 移動先のフォルダパスを取得して無ければ生成 | |
folder = new File ("${it.getParent()}\\${getFolderName(it.lastModified())}") | |
if (!folder.exists()) { folder.mkdir() } | |
it.renameTo(new File(folder, it.name)) | |
println "move ${it.name} \t-> ${new File(folder, it.name).getParent()}" | |
count++ | |
} | |
} | |
JOptionPane.showMessageDialog(null, "${count}件のファイルを移動しました。") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment