jiro4989
12/17/2017 - 6:26 AM

空のダミーファイルを生成するスクリプト(powershell, python, go)

空のダミーファイルを生成するスクリプト(powershell, python, go)

120.times do |i|
  fn = "rb/dummy%03d.zip" % i
  File.open(fn, "w") do |outfile|
    outfile.puts ""
  end
end
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def main():
    for i in range(0, 120):
        with open("py/dummy{0:03d}.zip".format(i), "w"):
            pass

if __name__ == '__main__':
    main()
0..120 | % {
  $num = ([string]$_).PadLeft(3, "0")
  echo "" > "ps1\dummy$num.zip"
}

ls ps1
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func init() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}

func main() {
	for i := 0; i < 120; i++ {
		filepath := fmt.Sprintf("go/dummy%03d.zip", i)
		var b []byte
		err := ioutil.WriteFile(filepath, b, os.ModePerm)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println("<" + filepath + "> is created.")
	}
}