# Move-Item is not working for existing folders and files

**URL:** <https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616>\
**Category:** PowerShell Help\
**Created:** [June 10, 2016, 12:21pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616 "2016-06-10T12:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [June 10, 2016, 12:21pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616/1 "2016-06-10T12:21:04Z")

</div>

My code snippet is below. I am trying to have items move into folders that already exist. The folders might actually have the files in them too. I want the code to move the file in to the folder and I want it to overwrite the existing file regardless, no matter what.

[PRE]

#If a date folder with the date of this item is already created, it is moved there  
If(test-path “\172.17.200.20\CDC\archive$datefolder”)  
{  
Add-content -Path $logpath -value “Date file already created. Moving item to date file in archive on old server.”  
$archive = “\172.17.200.20\CDC\archive$datefolder”  
Move-Item $item $archive -Force  
}

#If the date folder with the date of this item is not already created, the folder is created and then the item is moved to that location.  
else  
{  
Add-content -Path $logpath -value “Date file not already created. Creating date file in archive on old server.”  
New-Item -ItemType directory -Path “\172.17.200.20\CDC\archive$datefolder”  
$archive = "\172.17.200.20\CDC\archive" + $datefolder  
Add-content -Path $logpath -value “Now moving itme to date folder just created.”  
move-item $item $archive -Force  
}

[/PRE]

---

<div class="post-metadata">

**Author:** ![justin-king](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/justin-king/32/308_2.png) [@justin-king](https://forums.powershell.org/u/justin-king)\
**Post date:** [June 10, 2016, 12:32pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616/2 "2016-06-10T12:32:19Z")

</div>

without knowing the format of the $datefolder I have to guess a bit. Is it possible you have brackets or other special characters so you need to call out -litteralpath instead of the default -path? At face value the syntax looks correct.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 10, 2016, 12:35pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616/3 "2016-06-10T12:35:33Z")

</div>

Also, use angle brackets around PRE, not square brackets, to format code. See the syntax in the three bullets above the reply textbox.

---

<div class="post-metadata">

**Author:** ![jack-neff](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jack-neff](https://forums.powershell.org/u/jack-neff)\
**Post date:** [June 10, 2016, 4:20pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616/4 "2016-06-10T16:20:10Z")

</div>

In your script $archive contains only a string. It doesn’t represent an array of files. Try instead…

```
$archive = Get-ChildItem "\\172.17.200.20\CDC\archive\$datefolder" -Recurse
```

Edit: Never mind what I wrote, just re-read your post you’re moving the whole folder. Carry on.

---

<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:41pm UTC](https://forums.powershell.org/t/move-item-is-not-working-for-existing-folders-and-files/6616/5 "2024-05-16T20:41:05Z")

</div>


