0

First time posting.i would like to make multiple copies of a file and save all copies in a folder. I would like to name them individually from a list in CSV. I would prefer to do this in PowerShell. Any help is appreciated.

2
  • I want to make sure I understand the question correctly. You have some file (single) and another file (csv text file). You want to read the CSV and then make copies of the first file while renaming the copied file to the 'text' from the CSV? Commented May 20, 2017 at 10:41
  • 1
    Correct Jason and thanks for replying. I have an image. I want to create many copies of the image (lets say 30) Name the first image the text in the first row of the CSV file, name the 2nd image the text in the 2nd row of the CSV file etc etc. Obviously the number of images(files) would match the number of rows in the CSV file. Commented May 20, 2017 at 10:50

1 Answer 1

2

This has already been answered before so I recommend you review this question/answer:
Is there a single PowerShell command to copy and rename files?

I grab an image file off the internet and renamed it to original.png Inside my test folder I created a file called names.csv which contained the following:

test1,
test2,
test3

Then I added a script.ps1 file which contained the following:

Import-Csv e:\test\names.csv -Header newFileName | % { Copy-Item -Path e:\test\original.png -Destination "e:\test\output\$($_.newfilename).png" }

Last added an output folder and ran the script.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Jason. I had looked at that answer before but it doesn't answer my problem (as far as I can tell). I only have 1 column in my csv file. WHat do you mean update the CSv with correct information. It only has 1 field for each row.
Sorry, you are right, you would not have to update the CSV. I will update my answer above.
Thanks Jason. Appreciate your help. This only copies it once and names it without a name, just an extension.
Jasons script assumes a header in the csv file. If there is no header try: Import-Csv C:\test.csv -Header newfilename | % { Copy-Item -Path C:\originalFile.png -Destination "C:\TEST\$($_.newfilename).png" } otherwise replace newfilename with the actual Header from the csv file.
thanks lotspings, that worked. can i ask what constitutes a valid header? And can anyone suggest a goo place to start to learn powershell syndatx?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.