Skip to content

Instantly share code, notes, and snippets.

@nemo-kaz
nemo-kaz / findEncryptedZipFile.groovy
Created December 22, 2017 09:44
Recursively find encrypted zip file
// run findEncryptedZipFile.groovy in the root directory of Encrypted zip files
// to find out encrypted zip files recursively.
// run this code at the top directory of zip files.
// Output directory is d:\WORK\ENCRYPTED, modify the location to meet your environmnet
// Using maven https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j
@Grapes(
@Grab(group='net.lingala.zip4j', module='zip4j', version='1.3.2')
)
@echo off
rem this batch will call some batch file "updateIt.bat" at each 10 days
rem one line of log.txt is like 2017012 ("2017 Jan 20thday") and so on, if the last line of log.txt
rem is different from now, the next batch file will ba called.
rem So we can invoke updateIt.bat at each 10 days
rem Good for some cleanup acitivity
FOR /F "delims=," %%a IN (log.txt) DO (
IF %%a == %date:~0,4%%date:~5,2%%date:~8,1% (
goto DONE
@nemo-kaz
nemo-kaz / recursiveGrep.groovy
Created October 20, 2016 03:28
recursively grep with one or two keywords.
// g100pon recursively grep various filetype files with one or two keywords
// lastly invoke Hidemaru editor
startDir = "."
filePattern = /(\.asm.*$|\
\.awk$|\
\.bat$|\
\.BMS$|\
\.c$|\
\.cbl.*$|\
// 文字コード判定
// ソースコードのコードページを再帰的に判定し続ける
import com.ibm.icu.text.CharsetDetector
@Grab(group='com.ibm.icu', module='icu4j', version='56.1')
def detector = new CharsetDetector()
// UTF-8, UTF-16 UTF-32, Windows-31j
// ISO-8859-2, windows-1252, windows-1250, ISO-8859-2, ISO-8859-1, Big5, UTF-16LE
@nemo-kaz
nemo-kaz / listModifiedToday.bat
Created September 5, 2015 06:55
In windows command line, recursively list office files modified toay, file extentions having x (*.docx, *.pptx, *.dox, *.txt)
@REM Recursively list office files modified today ( Word Excel Powerpoint text)
FORFILES /P . /S /D %DATE% /M *.*x*
@nemo-kaz
nemo-kaz / TrigraphRemover.groovy
Last active August 29, 2015 14:14
Remove Trigraph from given source code
// Removing trigraph notation in the source code
//----------------------------------------------------------------------------
//| trigraph | replacement | trigraph | replacement | trigraph | replacement |
//----------------------------------------------------------------------------
//| ??= | # | ??( | [ | ??< | { |
//| ??/ | \ | ??) | ] | ??> | } |
//| ??’ | ? | ??! | | | ??- | ? |
//----------------------------------------------------------------------------
// From To
// ??= #
/** メインフレームのIBM EBCDIC半角カタカナを英小文字に変換するmetaClass操作*/
// before:アイウエオカキクケタチツテトナニヌネヘホマミムメモヤ
// after: abcdefghijklmnopqrstuvwxyz
String.metaClass.kana2ei = { ->
return delegate.tr('アイウエオカキクケタチツテトナニヌネヘホマミムメモヤ','abcdefghijklmnopqrstuvwxyz')
}
assert "ネオカオネオトウオ クイ0020 オトエ-ウアツツ".kana2ei()=="reference hb0020 end-call"
@nemo-kaz
nemo-kaz / fileSpaceRenamer.groovy
Created January 12, 2014 22:24
Remove space and special character from file name
// File Space Renamer
// Renames any file which has %20 %40 (space) : ;
// %20 -> _
// %40 -> @
// (space) -> _
// eg "Hello World.txt%40" -> "Hello_World@.txt"
new File(".").eachFile { file ->
if(file.isFile()){
curName = file.getPath().replaceAll(/.\\(.*)/) {m0,m1 -> m1}
newFileN = URLDecoder.decode(curName, "UTF-8").replaceAll(/%20/,"_").replaceAll(/%40/,"@").replaceAll(/ /,"_").replaceAll(/:/,"_").replaceAll(/;/,"_")
@nemo-kaz
nemo-kaz / PDFRenamer
Created December 21, 2013 04:59
PDFRenamer.groovy renames PDF file to the file by its Title metadata.
// PDF Renamer : Rename PDF file from the metadata Title
// 1: set PATH to pdftk
// 2: plase PDFRenamer.groovy (this file to same directory of pdftk )
// 3: move to the root of target PDF directory
// 4: start PDFRenamer.groovy in pdftk directory
@Grab('net.java.dev.jna:jna:3.4.0') // since Java does not have directory moving function
import com.sun.jna.*;
import com.sun.jna.win32.*;
@nemo-kaz
nemo-kaz / FREE.groovy
Created November 16, 2013 07:47
FREE command shows free space of each drive for Windows
//println "drv [ free ]G [ total ]G [free]%"
println "drv [ 空き ]G [ 計 ]G [Free]%"
allFree=0
allTotal=0
for (drive in "B".."Z") {
file = new File("${drive}:/")
BigDecimal free = file.getFreeSpace()/1000000000
allFree=allFree+free
BigDecimal total= file.getTotalSpace()/1000000000
allTotal=allTotal+total