## nanoMove.awk -v MAX_PATH=260　redirect
#
var MAX_PATH = 260
BEGIN {
	print "\e[92m# ls コマンドの出力を moveコマンドで振り分ける\e[m"
	print "\e[92m# 準備\e[m"
	set("CLEAN_FOLDER=0 DISPLAY_WIDTH=40 MAX_PATH=" MAX_PATH)
	CURT = "./"
	INPUT = "W:/"
	LONG = "W:/Long/"
	MOVE = "W:/MOVE/"
	TEMP = "W:/TEMP/"
	remove(MOVE)
	copy(CURT "MATRIX*.html", TEMP, "-r")
	path50 = "---+----1----+----2----+----3----+----4----+----5"
	path100 = path50 "----+----6----+----7----+----8----+----9----+----0"
	path200 = path100 "B" path100
	fileName = "/Z" path200 path50 "_5.txt"
	path = LONG "A" path200 fileName
	print "foo" > path

	redirect = ARGV[1]
	print "\e[92m# リダイレクト\e[m"
	ls(INPUT, ">" redirect)
	tree(INPUT, "file")

	print ""
	print "\e[92m# 振り分け\e[m"
}
	{
	if (length($0) > MAX_PATH) {
		out = $0;
		sub("^.*?/.+?/", MOVE, out)	# 出力フォルダ、W:/IN/foo/file -> O:/OUT/foo/file
		# sub("[^/]+$", "", out)		# (お好みで)ファイル名を削除、-> O:/OUT/foo/
		# copy($0, out)
		move($0, out)
		count += 1
	}
}
END {
	print "\e[92m# 確認\e[m"
	tree("W:/", "file")
	print "Total number of cases: " NR ", Number of processed: " count >"/dev/stderr"
	print "\e[92m# 完了\e[m"
	print ""
	print ""
	print ""
	print ""
	print ""
	print ""
}