1

I have a csv file that contains one column of cells (column A), each row/cell contains a single file name. The csv file has no header.

Something like this -

6_2021-05-10_02-00-36.mp4    
6_2021-05-10_05-04-01.mp4     
6_2021-05-10_05-28-59.mp4       
6_2021-05-10_05-35-05.mp4      
6_2021-05-10_05-35-34.mp4      
6_2021-05-10_05-39-36.mp4  
6_2021-05-10_05-39-41.mp4   
6_2021-05-10_05-39-52.mp4

The number of rows in this csv file is variable.

I need to add a URL to the beginning of the text in each cell, such that, a valid URL is created - and the resulting csv content looks exactly like this:

https:\\www.url.com\6_2021-05-10_02-00-36.mp4    
https:\\www.url.com\6_2021-05-10_05-04-01.mp4
https:\\www.url.com\6_2021-05-10_05-28-59.mp4
https:\\www.url.com\6_2021-05-10_05-35-05.mp4
https:\\www.url.com\6_2021-05-10_05-35-34.mp4
https:\\www.url.com\6_2021-05-10_05-39-36.mp4
https:\\www.url.com\6_2021-05-10_05-39-41.mp4
https:\\www.url.com\6_2021-05-10_05-39-52.mp4

So, this is what I've come up with, but it does not work.....

Param($File)  
$csvObjects = C:\_TEMP\file_list_names.csv $file 
$NewCSVObject = "https:\\www.url.com\"  
foreach ($item in $csvObjects)  
{  
    $item = ($NewCSVObject += $item)   
}  
$csvObjects | export-csv "C:\_TEMP\file_list_names_output.csv" -noType 

But it's not working, and my PowerShell skills are not so sharp. I'd be so very grateful for some assistance on this.

Thanks in advance- Gregg Sierra Vista, AZ

3 Answers 3

0

just concat with what you want:

$file2 ="C:\fic2.csv"
$x = Get-Content $file2

for($i=0; $i -lt $x.Count; $i++){

    $x[$i] = "https:\\www.url.com\" + $x[$i] 
}
$x
Sign up to request clarification or add additional context in comments.

2 Comments

Frenchy looks like that is writing it to the screen, but did not save the resultant csv content to a csv. What line would have to come after to save the pout put to a csv?
Figured it out - Add-Content -Path C:_TEMP\file_list_names_url.csv -Value $x THANKS!!!!!!!!!!!!
0

Technically speaking your inputfile can serve as csv, but because it contains only one column of data and has no headers, you can treat it best with Get-Content instead of using Import-Csv
Here's two alternatives for you to try.

$result = foreach ($fileName in (Get-Content -Path 'C:\_TEMP\file_list_names.csv')) {
    'https:\\www.url.com\{0}' -f $fileName
}
# next save the file
$result | Set-Content -Path 'C:\_TEMP\file_urls.csv'

OR something like:

Get-Content -Path 'C:\_TEMP\file_list_names.csv' | ForEach-Object {
    "https:\\www.url.com\$_"
} | Set-Content -Path 'C:\_TEMP\file_urls.csv'

Urls usually use forward slashes / not backslashes \.. I left these in, so you can replace them yourself if needed

Comments

0

With the help of Frenchy.... the complete answer is.... (URL changed for security reasons obviously)

#opens list of file names
$file2 ="C:\_TEMP\file_list_names.csv"
$x = Get-Content $file2
#appends URl to beginning of file name list
for($i=0; $i -lt $x.Count; $i++){

    $x[$i] = "https://bizops-my.sharepoint.com/:f:/g/personal/gpowell_bizops_onmicrosoft_com/Ei4lFpZHTe=Jkq1fZ\" + $x[$i] 
}
$x

#remove all files in target directory prior to saving new list
get-childitem -path C:\_TEMP\file_list_names_url.csv | remove-item

Add-Content -Path C:\_TEMP\file_list_names_url.csv -Value $x

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.