# Mulitple Basename(s) to one destination folder

**URL:** <https://forums.powershell.org/t/mulitple-basename-s-to-one-destination-folder/4716>\
**Category:** PowerShell Help\
**Created:** [August 18, 2015, 7:06pm UTC](https://forums.powershell.org/t/mulitple-basename-s-to-one-destination-folder/4716 "2015-08-18T19:06:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adnan-salahuddin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@adnan-salahuddin](https://forums.powershell.org/u/adnan-salahuddin)\
**Post date:** [August 18, 2015, 7:06pm UTC](https://forums.powershell.org/t/mulitple-basename-s-to-one-destination-folder/4716/1 "2015-08-18T19:06:26Z")

</div>

Hi folks,

How to multiple different file names without extension to a single folder? e.g

we have two different path name (D:\Folder\_1\aa.txt and D:\Folder\_2\bb.txt). I want only two filename without extension ($file.BaseName) to the same folder (D:\OtherFolder\aa.csv and …\bb.csv)

Here is my sample script as below:

$fileList = dir ‘D:\Folder\_1\aa.txt’,‘D:\Folder\_2\bb.txt’  
$destinaion = 'D:\OtherFolder'  
$newExtension = “.CSV”  
foreach ($file in $fileList){  
$file.BaseName  
Get-Content $file | ForEach-Object {($\_ -replace “\s+”,“,”)} |  
Out-File -FilePath $($destination + $newExtension) -Encoding OEM  
}

Any Idea? Thanks

---

<div class="post-metadata">

**Author:** ![peter-jurgens-2](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@peter-jurgens-2](https://forums.powershell.org/u/peter-jurgens-2)\
**Post date:** [August 18, 2015, 8:37pm UTC](https://forums.powershell.org/t/mulitple-basename-s-to-one-destination-folder/4716/2 "2015-08-18T20:37:41Z")

</div>

The first problem I notice is that you’re not using the file’s basename in your out-file command. Therefore in effect what you’re passing to the Out-File -FilePath parameter is in effect this: “C:\OtherFolder.CSV”.  
Try to create the whole filepath for the new file in one variable and pass that to the -FilePath parameter of Out-File  
My assumption from your code is that you’re trying to take a tab delimited file and convert it into a CSV, however, have you considered the -Delimeter parameter of Import-Csv? You can copy the files over like this:

```
Get-ChildItem 'D:\Folder_1\aa.txt','D:\Folder_2\bb.txt' | Copy-Item -Destination 'C:\OtherFolder'
```

Then if you need to import the files into your console use:

```
#note the backtick (`) before the t
Import-Csv C:\OtherFolder\aa.txt -Delimeter "`t"
```

EDIT: Actually I may have been hasty to respond. If your input file is delimited by “one space or more” then the “`t” won’t work, it needs to be a tab character, so you will still end up having to replace the “once space or more”.  
Could you share a sample of your input files? I could possibly provide a better solution knowing the structure of the content of the files.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/mulitple-basename-s-to-one-destination-folder/4716/3 "2024-05-16T20:44:55Z")

</div>

Closed on May 16, 2024, 8:44pm UTC


