Giter Site home page Giter Site logo

powershell-hashcopy's People

Contributors

markwragg avatar shayki5 avatar stilllearnin avatar wrobelda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

powershell-hashcopy's Issues

Source Path Enhancement

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

-Mirror parameter doesn't work properly

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:

  1. Copy a directory without the -Mirror switch
  2. Copy the same directory with the -Mirror and the -WhatIf switches - it will tell you that it's going to delete all the files

EDIT: After a bit more checking:
Not working: Copy-FileHash -Path C:\somePath -Destination C:\someOtherPath
Working: Copy-FileHash -Path C:\somePath\ -Destination C:\someOtherPath\

Old files are not removed in the destination folder

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.

Improvements

  • Look at using resolve-path instead of new-item to get the full path of the parameters.
  • Look at using split-path and join-path when determining the dest path (currently via regex) as this is likely less error-prone plus would likely make the cmdlet cross-platform compatible (e.g at the moment we hard code a backslash where on Linux this would likely fail?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.