# Powershell- Duplicating Files in same folder Please!

**URL:** <https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271>\
**Category:** PowerShell Help\
**Created:** [May 9, 2022, 6:35pm UTC](https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271 "2022-05-09T18:35:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellen\_dorandt89](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@hellen\_dorandt89](https://forums.powershell.org/u/hellen_dorandt89)\
**Post date:** [May 9, 2022, 6:35pm UTC](https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271/1 "2022-05-09T18:35:44Z")

</div>

Hello Powershell Noob here, I am trying to write a script that will take paths from my clipboard and just duplicate them right in their parent folder.

Lets say my clipboard looks like this:

```auto
"C:\Users\User1\New Folder\Image A.jpg"
"C:\Users\User1\New Folder\Image B.jpg"
"C:\Users\User1\New Folder\Image C.jpg"

```

I know its just a matter of `Copy-Item` but I am stuck on correctly appending “`(1)`” on the file name each file name. I’ve tried:

```powershell
$objectList = Get-Clipboard
Foreach($Object in $ObjectList){
$i
$NewName = Join-Path -Path $Object -ChildPath ((Split-Path $Object -Leaf) + $i)
Copy-Item -Path $Object -Destination $NewName}

```

Sometimes I get a result like:

```auto
"C:\Users\User1\New Folder\Image A.jpg1"

```

but I mostly just end up getting red errors, I’ve read the docs and trawled stack overflow and I’ve gotton even more confused.

Can anyone help me understand how to do this? Thanks!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 9, 2022, 6:46pm UTC](https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271/2 "2022-05-09T18:46:41Z")

</div>

Hellen,  
Welcome back to the forum. 👋🏽

Do you want to rename the files or do you want copy them in the same folder or do you want to move them to the parent folder?

I’d recommend to create proper objects for each individual file with `Get-Item` or even use `Get-ChildItem` initially instead of using the strings from the clipboard. This way you can easily access the individual elements of the file. Such as `BaseName` and `Extension.`

If you want to copy the files in the same folder it should be enough when you only rename the `BaseName`. 😉

And BTW When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

> <https://stackoverflow.com/questions/72176755/duplicating-files-in-same-folder>

---

<div class="post-metadata">

**Author:** ![hellen\_dorandt89](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@hellen\_dorandt89](https://forums.powershell.org/u/hellen_dorandt89)\
**Post date:** [May 10, 2022, 10:44am UTC](https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271/3 "2022-05-10T10:44:51Z")

</div>

I agree with your suggestion, I will link to other posts next time. Thanks again for helping once more.

---

<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:17pm UTC](https://forums.powershell.org/t/powershell-duplicating-files-in-same-folder-please/19271/4 "2024-05-16T20:17:56Z")

</div>

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


