markwragg / powershell-hashcopy Goto Github PK
View Code? Open in Web Editor NEWA PowerShell module for copying files between two paths that have been determined to have changed via computed hash value comparison.
A PowerShell module for copying files between two paths that have been determined to have changed via computed hash value comparison.
function Get-DestinationFilePath {
<#
.SYNOPSIS
Accepts a source and destination file paths and a file (that from the source path) and returns the equivalent destination path (regardless of whether it exists).
.PARAMETER File
The file to modify.
.PARAMETER Source
The source directory or file path.
.PARAMETER Destination
The destination path.
.EXAMPLE
Get-DestinationFilePath -File (Get-ChildItem c:\temp\somefile.txt) -Source c:\temp -Destination d:\example
#>
[cmdletbinding()]
param(
[Parameter(Mandatory)]
[System.IO.FileInfo]
$File,
[Parameter(Mandatory)]
[String]
$Source,
[Parameter(Mandatory)]
[String]
$Destination
)
if (Test-Path -Path $Source -PathType leaf) {
$Source = Join-Path (Split-Path -Parent $Source) -ChildPath '/'
}
$DestFile = Join-Path (Split-Path -Parent $File) -ChildPath '/'
$DestFile = $DestFile -Replace "^$([Regex]::Escape((Convert-Path $Source)))", $Destination
$DestFile = Join-Path -Path $DestFile -ChildPath (Split-Path -Leaf $File)
Return $DestFile
}
Making the change above allows for the main Copy-FileHash function to accept an array of file paths rather than just directory paths. E.g.:
# files to copy
$SourceFiles = @()
$SourceFilesFilter = @("*.ZIP")
$SourceDirectories = @($DATSourceDirectory)
$SourceDirectories | ForEach-Object {
$SourceFiles += (Get-ChildItem -Path $_ -Recurse -Include $SourceFilesFilter -File).FullName
}
# copy files from source to temp
Copy-FileHash -Path $SourceFiles -Destination $DATTempDirectory
Hey, this module is really awesome! However, the -Mirror
parameter doesn't work correctly for me - it deletes all of the files I want to copy across for some reason. A way to reproduce it is:
-Mirror
switch-Mirror
and the -WhatIf
switches - it will tell you that it's going to delete all the filesEDIT: After a bit more checking:
Not working: Copy-FileHash -Path C:\somePath -Destination C:\someOtherPath
Working: Copy-FileHash -Path C:\somePath\ -Destination C:\someOtherPath\
Hi,
I am using Copy-FileHash to copy files from source folder to destination folder.
However when the the destination folder already contain files that do not exist in the source folder, these files are not deleted.
I want to make sure that by the end of operation, both source and destination contain the same total number of files.
Can I achieve this this using Copy-FileHash without first clearing the destination folder?
Thanks.
Current build image is no longer available.
From PaulBrand:
Hello, Mark! Your module is almost PERFECT for what I need to do--I'm pretty geeked to have found it.
One question: is it possible to have HashCopy completely mirror two directories? In other words, can it remove files from the destination that have been removed from the source?
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.