H want to copy some photos from a folder to another. in the folder has a lot of photos, but I only want to copy a certain filename that i input to a multiple textbox.
this is what I did so far:
` $USBFolder = "F:"
$Filname = $Textbox.Text -split ','
$ImageSource = "c:\Folder"
$Filnename | ForEach-Object {Get-ChildItem -FIlter *.jpg | Where-Object {$_.Basename -match $Filename} | Copy-Item -Destination $USBFolder -Force} `
But it didnt do anything. please tell me what I do wrong?
Avoid using to many conditions and Cmdlets in a single pipeline.
Is not performatic, and it makes it hard to debug.
Do it step by step, specially if you're not experienced in PS.
Try out this code, and read the comments.
In your case, using -match is not ideal, because -match uses regex, which can complicate things for simple file names.
Is important to notice that in the first 'if', we are checking if a text is 'in' a list of text. So the text in the list must be equal the file base name.
On the second 'if' we are looking for files which contain the text of at least one text in the list.
Hope it helps!