[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

It's just a Notepad text file.

5

I have a script that duplicates a Word doc template and renames each using a csv file with a list of names. What would be the equivalent code if instead of a csv file I use a text file?

Import-csv ‘.\individuals2.csv’ | foreach-object {
	$newname = ‘2 ‘ + $_.name + '.docx’
	Copy-item '.\template.docx' $newname
}
[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Thanks but PS closes so I assume it ran into an error. I'm not sure why because there is the same number of files and list items. I doublechecked to make sure.

[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Also I had someone help with a similar task of duplicating a Word file that is renamed from a list of names found in a csv file. What would be the code when a txt file is used?

Import-csv ‘.\individuals.csv’ | foreach-object {
    $newname = ‘2’ + $_.name + '.docx’
    Copy-item '.\_2023 Summary Page.docx' $newname
}
[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Yeah it's a pretty simple task and I'm interested in getting more familiar with PS.

[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Thanks but I'm getting a 'Cannot create a file when that file already exists.' error. I checked the path so I am certain it is correct.

[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Perhaps my directions were unclear. The Excel/CSV file has the new names and I want to use them to replace the default names for the PDF files.

[-] BobTheDestroyer@lemy.lol 2 points 8 months ago

I got rid of that task. Now it's just Task #1

[-] BobTheDestroyer@lemy.lol 2 points 8 months ago

Nevermind I got it!

11
submitted 8 months ago* (last edited 8 months ago) by BobTheDestroyer@lemy.lol to c/powershell@programming.dev

Note: I'm a beginner to Powershell and a bit more familiar with Bash (though still a beginner for that too).

*I have multiple PDF files and I want to rename each file based on a list of names found in an Excel/CSV (could be a text file if easier) file.

*The list begins at the A2 cell and the A1 cell has the header 'name'.

*The files are in sequential order and match the order of the list of names.

Thanks for your help!

[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

So I'm new to all this. When I enter the first command with my csv file and doc file included, it just opens the word doc. Wasn't sure what I should do next.

[-] BobTheDestroyer@lemy.lol 1 points 8 months ago

Sorry I'm new to this. What exactly do I enter into Powershell for each step?

[-] BobTheDestroyer@lemy.lol 2 points 8 months ago

It does have to be a Word template. It has a bar graph and various texts.

10

I'm a beginner to Powershell and CLI in general, but this task does not need to use either so I'm open to using other tools.

I'm trying to do the following:

  1. Create multiple files from a Word template.
  2. Rename each file based on a list of names found in an Excel/CSV sheet.

Thanks in advance!

view more: next ›

BobTheDestroyer

joined 8 months ago