EDIT: So after some research, since what I had wasn't quite doing the trick and the advice and comments from before got me further along than I was previously, I am back with a bit more research and a more complete script.

```
Import-CSV C:\saveme\file_path3.csv | ForEach-Object {
Get-ChildItem $_.path -Recurse  | ForEach-Object {
$split = $_.FullName  -split '\\'
$DestFile =  $split[1..($split.Length - 1)] -join '\' 
$DestFile =  "G:\Recuva2\$DestFile"
$null = New-Item -Path $DestFile -Type File -Force
If (Test-Path $DestFile) {
$i = 0
While (Test-Path $DestFile) {
$i += 1
$DestFile = $DestFile+$i
}
} Else {
$null
}
Copy-Item -Path  $_.FullName -Destination $DestFile -Verbose -Force
}
} 

```

This seems to be breaking due to an inability to find the destination directory. It seems to be breaking on this line

```
$null = New-Item -Path $DestFile -Type File -Force

```

and this line

```
Copy-Item -Path  $_.FullName -Destination $DestFile -Verbose -Force

```

The common denominator here seems to be the $DestFile. I understand I am doing a good bit to the $DestFile, but I can't seem to nail down what is causing it to break.

My desired end-result here is that the folder structure be maintained when copying the specific files over in the csv list from which I am importing.

What actually seems to be happening is that it is throwing errors whenever I attempt to copy. Error text below.

```
Copy-Item : Could not find a part of the path 'G:\Recuva2\HR_VIOLATORS\REPORTS\REPORT_Storage2\199452\1.3.6.1.4.1.11157.2011.3.21.8.12.5.52516\1.3.51.5156.1369.20110321.1190709\1.3.51.0.7.3750462839.61413.18976.39828.11247.2380.39394'.
At line:16 char:5
+     Copy-Item -Path  $_.FullName -Destination $DestFile -Verbose -Force
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItem 
Command

```

-- END EDIT

ORIGNAL POST:

Similar to but not quite the same as

[Keep rename duplicate items with copy](https://stackoverflow.com/questions/46963312/keep-rename-duplicate-items-with-copy)

Essentially I am being forced to grab a list of directories from a csv file and copy their contents. However the problem I am having is that some of the directories and files are duplicated.

I am attempting to use this script to import from the csv, copy the files with directory structure intact, while renaming any duplicates, ideally at the file level so that the duplicate directories are merged.

```
Import-CSV C:\COPYME\file_path.csv | foreach($_.path) {
ls $_.path -recurse  | foreach($_) {
$SourceFile = $_.FullName
$DestinationFile = "G:\Recuva2\"+$_
If (Test-Path $DestinationFile) {
    $i = 0
    While (Test-Path $DestinationFile) {
        $i += 1
        $DestinationFile = "G:\Recuva2\"+$_+$i
    }
} Else {
    New-Item -ItemType File -Path $DestinationFile -Force
}
Copy-Item -Path $SourceFile -Destination $DestinationFile -verbose -Force
}
}

```

I am receiving an error that says that line 2 character 24 cannot be resolved to a method? What am I missing/doing wrong here?