Search code examples
powershellfiledirectorymove

Powershell - move folders and all its contents to another folder


I have a folder H:\FAKTURA with a bunch of folders in it. In the same folder I have a folder named "ARKIV". I want to move all folders in this folder to the "ARKIV" folder.

I have the following but nothing happens, no errors, no moving of folders/files

 $current_logfiles = "H:\FAKTURA\"
 $destination = "H:\FAKTURA\ARKIV\"

 if ((Test-Path -Path $destination)) 
 {
     Move-Item -Path $current_logfiles -Destination $destination - 
     Exclude "H:\FAKTURA\ARKIV"  -force
 }

I got "Access to path "H:FAKTURA" is denied" Is there something I am missing here..? I have full access to this folder, I can manually do this. And I am running powershell as Administrator too, but no success :(

enter image description here

enter image description here


Solution

  • You stated that H:\FAKTURA\ARKIV which would mean that Test-Path -path $destination would come back as True. Problem is that you then negate the result !(Test-Path -path $destination) which would come back as False and hence the If statement will not work. Remove the '!()'