Search code examples
xcopy

Copying files from directory structure with a wildcard in the path


This seems extremely simple, but I somehow can't get it to work, so hoping you guys can help.

I have a very large Winforms solution that i'm trying to extract all dll's following a build. My build pushes all dll's into a folder within each project during the build, so that I end up with a similar file structure.

Structure would be like this but with varying project names:
C:\solution\project1\bin
C:\solution\project2\bin
C:\solution\project3\bin

I thought it would be really easy to run an xcopy command like below to copy to a single location, but i'm not sure how to use a wildcard in the path:
xcopy C:\solution\???\bin\*.dll C:\Output

Is this possible with xcopy? If not, any other suggestions, maybe powershell?

Thanks for any help you can provide.


Solution

  • A Powershell Solution:

    $srcPath  = "C:\mySource"
    $destPath = "C:\myDest"
    
    # Generate List of files with the .dll extension in $srcPath
    $fileList = (Get-ChildItem -Path $srcPath | Where-Object {$_.Extension -eq     ".dll"}).FullName
    
    # Copies files to new destination $destPath
    foreach ($file in $fileList){
        Move-Item -Path $file -Destination $destPath
    }
    

    Just replace the $srcPath and $destPath variables with the desired locations.