Steve
Steve

Reputation: 1

Powershell Script for Windows server

I have file csv:

in *.csv is:

1;folder name 1
2;folder name 2
3;folder name 3
4;folder name 4

... up to 1212

The problem is that, I want to find a file by name "1" from file *.csv and create folder "folder name 1" and move this file to folder. Script is for Windows Server.

Upvotes: 0

Views: 46

Answers (1)

Paweł Dyl
Paweł Dyl

Reputation: 9143

This should work:

Import-Csv yourfile.csv -Delimiter ";" -Header File,Folder | % {
    New-Item -ItemType directory $_.Folder -Force;
    Move-Item -Path ($_.File) -Destination (Join-Path $_.Folder $_.File) -Force
}

Upvotes: 1

Related Questions