Morning Powershell users, I'm trying to copy files listed in a .CSV document from one directory to another based on their file name. My .CSV document is just one column of filenames, it looks like this:
2.jpg
4.jpg
5.jpg
8.jpg
12.jpg
I have a folder of .jpgs from 1-900 in G:\Numbered\ and a destination folder for where the files should go at G:\Selections. This seems like it should be relatively simple but I think I'm missing something in my code. This is what I have so far:
import-CSV G:\fileList1.csv | foreach {copy-item G:\Numbered G:\Selections}
I looked around and I think I may need to use Get-Childitem but I'm not sure where. Any help is greatly appreciated, thank you!
Assuming your CSV look like this:
YourColumnName
2.jpg
4.jpg
n.jpg
Try this:
Import-Csv fileList1.csv | ForEach {Copy-Item "G:\Numbered\$($_.YourColumnName)" G:\Selections }
But, if your CSV has only 1 column without a header, like this:
2.jpg
4.jpg
n.jpg
you should use Get-Content
because it's not really a csv file. And your code should be:
Get-Content files.csv | ForEach {Copy-Item G:\Numbered\$_ G:\Selections }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With