Home > Mobile >  Moving files based on CSV values
Moving files based on CSV values

Time:11-19

noobie here.

I have a csv file with two columns, they specify source files paths and destinated paths. I have around 1500 lines to execute. Is there any way to batch process this via a bat file or anything else?

A line in my CSV looks like this:

Source Path,Dest Path
C:\Users\Nick\Pictures\XXXXXXX.img,C:\Users\Nick\Pictures\Export\XXXXXXX.img

CodePudding user response:

I'd probably not solve this with batch files, but rather with PowerShell. It's possible in batch, but notoriously unreliable, especially around characters you don't expect when starting out.

In PowerShell this could be as simple as

Import-Csv files.csv | ForEach-Object {
  Move-Item -LiteralPath $_.'Source Path' -Destination $_.'Dest Path'
}

You might need to create directories as required, perhaps something like this:

Import-Csv files.csv | ForEach-Object {
  New-Item -ItemType Directory (Split-Path -Parent $_.'Source Path')
  Move-Item -LiteralPath $_.'Source Path' -Destination $_.'Dest Path'
}
  • Related