Created
November 4, 2015 02:19
-
-
Save smallgeek/46cd71309454d42fbeaf to your computer and use it in GitHub Desktop.
ファイルが初期化されることを確認するため事前にマーキングする
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
| open System | |
| open System.IO | |
| open System.Drawing | |
| type Kind = Text | Image | |
| let recognize filePath = | |
| let ext = Path.GetExtension(filePath).ToLowerInvariant() | |
| match ext with | |
| | ".bmp" | |
| | ".jpg" | ".jpeg" | |
| | ".png" | |
| | ".gif" | |
| -> Image | |
| | _ -> Text | |
| let marking filePath = | |
| match recognize filePath with | |
| | Text -> | |
| use stream = new FileStream(filePath, FileMode.Append, FileAccess.Write) | |
| use writer = new StreamWriter(stream) | |
| writer.WriteLine("## MARKING ##") | |
| printfn "Text marking (%s)" filePath | |
| | Image -> | |
| use buffer = new MemoryStream(File.ReadAllBytes(filePath)) | |
| use image = Bitmap.FromStream(buffer) | |
| use g = Graphics.FromImage(image) | |
| g.DrawString("## MARKING ##", SystemFonts.DefaultFont, Brushes.Red, PointF.Empty) | |
| image.Save(filePath) | |
| printfn "Image marking (%s)" filePath | |
| let allFiles targetDir = | |
| let files = Directory.EnumerateFiles(targetDir, "*.*", SearchOption.AllDirectories) | |
| files | |
| [<EntryPoint>] | |
| let main argv = | |
| Environment.CurrentDirectory | |
| |> allFiles | |
| |> Seq.iter marking | |
| 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment