Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Powershell, how can I move all files in a folder to a new child directory?

I've tried mv c:\foo\* c:\foo\bar\, but all my files disappear and I get an extension-less 'bar' file. I've also tried making the directory first and then doing the move, but I get a The process cannot access the file because it is being used by another process error, presumably because it is then trying to move the 'bar' folder to itself.

share|improve this question
    
Yes. It is trying to move C:\foo\bar into itself. The only workaround I can think of is temporarily moving \bar outside of \foo until the files are moved. Im not familiar with powershell, but If it supports wildcards like unix does, this should exclude directories: "mv c:\foo\*.* c:\foo\bar\" as long as all the files have an extension –  wolfo9999 Aug 17 '13 at 19:21
add comment

1 Answer

robocopy "c:\foo\ c:\foo\bar\"

The above works fine for just files in a folder.

A script/powershell example, please adjust args and options for your needs:

$args = "/COPYALL /B /SEC/"
$options = "/R:0 /W:0 /NFL /NDL"
$source = "c:\foo\"
$dest = "c:\foo\bar"

robocopy "$source $dest $args $options"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.