0

I currently have a script that will loop through a group of files in a folder - open each one up and let me enter a new file name and then rename it. I am then trying to create a CSV file with the old name in one column and the new name of the file in the second column.

#[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
Add-Type -AssemblyName Microsoft.VisualBasic 

$folderpath = 'C:\Scans\docs\' '#
$items = Get-ChildItem -Recurse $folderpath *.pdf
$newFileName = "" 
$counterID = 0
$amountOfScans = $items.Length

foreach( $i in $items)  {
    Start-Process ((Resolve-Path ("$folderpath$i")).Path)

    Start-Sleep -Seconds 1

    $counterID++ 

    $newFileName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the new file name $counterID / $amountOfScans :", $i) 

    Stop-Process -Name "Acro*"

    Add-Content -Path 'C:\Scans\fileNames.csv' -Value "$i","$newFileName "

    Rename-Item $i.FullName ("$newName.pdf")
}

This does work but it outputs into the csv only in the first column like:

old file name 1
new file name 1
old file name 2
new file name 2

How do make this output:

old file name 1 | new file name 1
old file name 2 | new file name 2

1 Answer 1

2

You're passing an array. A CSV is nothing more than a text file, so you want to pass the entire line as a single string.

Add-Content -Path 'C:\Scans\fileNames.csv' -Value "`"$i`",`"$newFileName`""
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this is exactly what I was looking for :)
Glad I could help. Please mark this as the answer if it solved your question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.