Powershell Match Filename with the same base name but different file extensions and copy them to a different folder

Powershell version 2

Need shell help, get a directory like the example below. Where there are many files, the common property is the name, but with different extensions. I need to rewrite through the directory the match with the same base name and copy them to the location. The files need to be copied to the destination together.

Sample files. 40127.wav, 40127.txt, 40127.ini, 40128.wav, 40128.txt, 40128.ini

My example script Works for only one element of the array. As I am calling the array member using $ test [0] to match the base name. Not sure how to get it to loop through the array as I seem to be breaking the foreach command.

$ source = c: \ audio

$ test = Get-ChildItem -Path $ source

foreach ($ item in $ test)

{get-childitem -path $ source -recurse | where {$ _. basename -eq $ test [0] .basename} | Move-Item -Destination C: \ Backup}

Result 3 files in C: \ backup 40127.wav, 40127.txt, 40127.ini.

Any help is greatly appreciated.

+3
arrays


source to share


No one has answered this question yet

Check out similar questions:

1
Calculating an array using powershell
0
How to search Powershell array for specific strings and use that result in -include instance script
0
C # Remove substrings from String array
0
Powershell, How to match filenames with partial names stored in a text file
0
How to copy a newly created array containing files to another folder on the same computer
0
copy files from one folder to another only if their filename is specified in the specified C # text file
0
Copy an item from one array to another in PowerShell
0
Copy-item excluding files and folders in powershell
-1
Copy files to folder using java 7 copy file method
-2
How can I read filenames from a folder and add them to an arraylist without having to create an array and loop through all responses in an arraylist?



All Articles
Loading...
X
Show
Funny
Dev
Pics