I have the following text file (tab delimited) that maps a specific file to a folder. I start with importing this csv:
SourcePathFile DestinationPath
C:\Test\Source\SourceDir 1\pic1.jpg C:\Test\Destination\Folder, 1
C:\Test\Source\SourceDir 1\Pic 2.jpg C:\Test\Destination\Folder 2
By using:
Import-csv -Delimiter `t "C:\Test\FileMapping.csv"
This gives me the array I want, so I figured that it would be a simple For-each to go through each line using
Copy-Item SourcePathFile DestinationPath
I'm clearly missing the general concepts
Assuming that your input file is valid TSV (is comma at the end of the line 2
is intended?) you can do this using pipeline:
Import-Csv -Path 'C:\Test\FileMapping.csv' -Delimiter "`t" |
ForEach-Object {Copy-Item -Path $_.SourcePathFile -Destination $_.DestinationPath}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.