Skip to content

Instantly share code, notes, and snippets.

@humhei
Last active December 20, 2018 01:20
Show Gist options
  • Save humhei/d2fda9e0daae68039cf851bc322f95ea to your computer and use it in GitHub Desktop.
Save humhei/d2fda9e0daae68039cf851bc322f95ea to your computer and use it in GitHub Desktop.
Rename project files
#if FAKE
#r "paket:
nuget Fake.Core.Target
nuget Fake.DotNet.Cli
nuget ExcelDna.Interop
nuget ExcelDna.Integration
nuget Fake.DotNet.MSBuild //"
#endif
#if !FAKE
#r "netstandard" // windows
#endif
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open System.IO
open Fake.IO
let origin = "State"
let dest = "Atrous"
let dir = __SOURCE_DIRECTORY__
let print() =
!! ("./**")
|> Seq.iter (printfn "%s")
let renameFile() =
// Shell.rename test2 test1
!! ("./**")
|> Seq.iter (fun file ->
if Directory.Exists file then ()
else
let fileName = Path.GetFileName file
if fileName.Contains(origin) then
let dir = Path.getDirectory(file)
printfn "%s" file
let newFileName = fileName.Replace(origin,dest)
let newFile = dir </> newFileName
if File.exists newFile then File.delete file
else
printfn "%s" newFile
Shell.rename newFile file
)
let rec renameDir() =
!! ("./**")
|> Seq.iter (fun oldDir ->
if Directory.Exists oldDir then
let dirName = Path.GetFileName oldDir
if dirName.Contains(origin) then
let dirRoot = Path.getDirectory(oldDir)
printfn "%s" oldDir
let newDirName = dirName.Replace(origin,dest)
let newDir = dirRoot </> newDirName
if File.exists newDirName then File.delete oldDir
else
printfn "%s" newDir
Shell.rename newDir oldDir
)
renameFile()
renameDir()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment