Skip to content

Instantly share code, notes, and snippets.

@FoleyAxel
Created August 21, 2012 18:24
Show Gist options
  • Select an option

  • Save FoleyAxel/3418145 to your computer and use it in GitHub Desktop.

Select an option

Save FoleyAxel/3418145 to your computer and use it in GitHub Desktop.
Folder Sync
open System
open System.Diagnostics
open System.IO
open System.Diagnostics
open System.Security.Cryptography
open System.Text.RegularExpressions
open System.Windows.Forms
let args = Environment.GetCommandLineArgs()
let sourceFolder = @"c:\compare\Source"
let destFolder = @"c:\compare\Dest"
let fileVersion fileName =
""//FileVersionInfo.GetVersionInfo(fileName).FileVersion
let rec findFiles (rootFolder:string) (folder:string) = seq {
let dirInfo = new DirectoryInfo(folder)
let filelist = dirInfo.GetFiles()
for file in filelist do
sprintf "%s\t%s\t%i" (file.FullName.Remove(0, rootFolder.Length+1)) (fileVersion file.FullName) file.Length |> Console.WriteLine
yield (file.FullName.Remove(0, rootFolder.Length+1), (fileVersion file.FullName, file.Length))
for dir in dirInfo.GetDirectories() do yield! findFiles rootFolder dir.FullName
}
type Agent<'T> = MailboxProcessor<'T>
let agent =
Agent.Start(fun inbox ->
async { let form = new Form()
do form.Width <- 350
do form.Height <- 55
do form.FormBorderStyle <- FormBorderStyle.FixedSingle
do form.Text <- "Folder Sync"
let progressBar1 = new System.Windows.Forms.ProgressBar()
do progressBar1.Location <- new System.Drawing.Point(0, 0)
do progressBar1.Name <- "progressBar1"
do progressBar1.Size <- new System.Drawing.Size(340, 35)
do progressBar1.Value <- 10
progressBar1.Increment(60)
do form.Controls.Add(progressBar1)
form.Show()
while true do
let! (inc) = inbox.Receive()
progressBar1.Increment(inc)}
)
let sourceList = findFiles sourceFolder sourceFolder |> Map.ofSeq
let destList = findFiles destFolder destFolder |> Map.ofSeq
let outdatedList = sourceList
//|> Map.iter (fun k (x,y) -> sprintf "%s\t%s\%i" k x y |> Console.WriteLine)
|> Map.filter (fun k v -> destList.ContainsKey(k) <> true || destList.[k] <> v )
outdatedList
|> Seq.iteri (fun i x -> sprintf "Updating %s...[%i/%i]" x.Key (i+1) outdatedList.Count |> Console.WriteLine
let src = sprintf "%s\%s" sourceFolder x.Key
let dst = sprintf "%s\%s" destFolder x.Key
let dir = Path.GetDirectoryName(dst)
if Directory.Exists(dir) then
File.Copy(src, dst, true)
else
let tf = Directory.CreateDirectory(dir)
File.Copy(src, dst, true)
agent.Post(100 / outdatedList.Count)
)
sprintf "Updating version info inside registry..." |> Console.WriteLine
//RegistryKey readRegKey;
//let readRegKey = Registry.LocalMachine.OpenSubKey("Software\\purkinje\\billingupdater", false)
//let keys = readRegKey.GetValue("clientID")
//if keys.ToString().Length > 0 then
// textBox2.Text = keys.ToString()
//System.Diagnostics.Process.Start((destFolder + @"\setup.exe")) |> ignore
Console.ReadLine() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment