Created
April 17, 2019 02:59
-
-
Save voronoipotato/b354a10181ebbca193b8b26677db87cd 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.IO | |
| open System.Text.RegularExpressions | |
| //__SOURCE_DIRECTORY__ is a keyword that represents the working directory in the commandline | |
| let sourceDirectory = __SOURCE_DIRECTORY__ | |
| let fileNames = Directory.GetFiles sourceDirectory | |
| printf "%s" sourceDirectory | |
| //fsi.CommandLineArgs is the list of command line arguments | |
| // [file.fsx; arg1; arg2] | |
| let args : string array = fsi.CommandLineArgs |> Array.tail | |
| // the regex pattern to be replaced | |
| let pattern :string = args.[0] | |
| printf "%s" pattern | |
| //the text we want it to be replaced to | |
| let replacement :string = args.[1] | |
| printf "%s" replacement | |
| //the array of files to be renamed | |
| let filesToBeRenamed = | |
| fileNames | |
| |> Array.filter (fun s -> s.Contains pattern) | |
| //the array of files with the name we would like them to have | |
| let renamedFiles = | |
| filesToBeRenamed | |
| |> Array.map (fun t -> Regex.Replace (t, pattern, replacement)) | |
| //zip together and rename | |
| Array.zip filesToBeRenamed renamedFiles | |
| |> Array.iter (fun (s,t) -> File.Move (s,t)) | |
| |> ignore | |
| 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment