-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
26 lines (24 loc) · 912 Bytes
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
open System
open System.IO
let renameAllFiles searchStr replaceStr confirmed =
let renameFile (oldFileName: string) =
let newFileName = oldFileName.Replace(searchStr, replaceStr, StringComparison.CurrentCultureIgnoreCase)
match confirmed with
| true -> File.Move(oldFileName, newFileName)
| false -> printfn $" {oldFileName} -> {newFileName}"
Directory.GetFiles(".", $"*{searchStr}*")
|> Array.map (fun f -> f.Substring(2))
|> Array.iter renameFile
[<EntryPoint>]
let main args =
match args with
| [| searchStr; replaceStr |] ->
renameAllFiles searchStr replaceStr false
1
| [| searchStr; replaceStr; "CONFIRM" |] ->
renameAllFiles searchStr replaceStr true
0
| _ ->
printfn "Renames all files in a directory. Syntax:"
printfn "RenameAllFiles.exe searchString replaceString [CONFIRM]"
1