• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 25
  • Last Modified:

How to move files and folders into a folder that is part of the same folder tree ?

Hello, I have the following code but i am getting access denied.

I need to move everything from "C:\ArchiveDocs\DocImageExports\Servicing" into "C:\ArchiveDocs\DocImageExports\Servicing\Old"

Move-Item -Path "C:\ArchiveDocs\DocImageExports\Servicing" -Destination "C:\ArchiveDocs\DocImageExports\Servicin
g\Old"

Open in new window


Error:
Move-Item : Access to the path 'C:\ArchiveDocs\DocImageExports\Servicing' is denied.

Open in new window


Thanks for your help
0
namerg
Asked:
namerg
  • 4
  • 2
2 Solutions
 
aikimarkCommented:
With that statement, you are trying to move a folder into a sub-folder.  Do you really want to move all the files into the sub-folder?
0
 
namergSystems AdministratorAuthor Commented:
Yes. Into the sub-folder "Old"
0
 
mlmccCommented:
You can't move a folder into a subfolder.  You have to specify the files in the folder and move them into the subfolder.

mlmcc
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
aikimarkCommented:
Please test this:
Get-ChildItem -Path "C:\ArchiveDocs\DocImageExports\Servicing" | ? {$_.psiscontainer -eq $false} |
% {Move-Item -path $_.fullname -Destination "C:\ArchiveDocs\DocImageExports\Servicing\Old"}

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
That script does not nothing. :(
0
 
namergSystems AdministratorAuthor Commented:
I got it.

This code did the trick.

Get-ChildItem -Path "C:\ArchiveDocs\DocImageExports\Servicing" | Where-Object {$_.Name -ne "Old"} | ForEach-Object {Move-Item -path $_.fullname -Destination "C:\ArchiveDocs\DocImageExports\Servicing\Old"}

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
The code did the requested question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now