I have a directory with sub directories, and I want to copy a file from each of these subdirectories into a single new directory but WITHOUT the sub directory structure.
\\server\sub1\file1.txt to \\myserver\file1.txt
\\server\sub2\file2.txt\ to \\myserver\file2.txt.
.... etc.
So I would like to COPY \\server\ as the SOURCE, check the Include sub directories box, give it a file mask file*.txt and then have a destination of \\myserver\ with an option to NOT create the sub directory structure of sub1, sub2 etc.
I have LOTS of sub directories.
In the general case, that has a lot of potential for naming collision, which I suspect is related to why there isn't built-in support for this.
I recommend using powershell. An off-the-cuff outline for accomplishing that (hopefully I'm getting the syntax right):
$list = Get-ChildItem \\server\ -Recurse -File
# I recommend a check here for filename collisions
$list | copy-item -Destination \\myserver\
# If you know for sure you don't need collision checking, you can one-line it:
gci \\server\ -Recurse -File | cp -Destination \\myserver\
...Disclaimer: I'm running Powershell 3 locally and I don't remember when the -File switch was added. The syntax for "just files, don't list directories" might have been more verbose in 2.0.
You can pass the -WhatIf flag (at least in 3.0) to the copy action to make sure it's going to do what you want before you do it. I should have done that when I tested it...I left off the -File switch the first time, and...yeah, don't do that.
Edited by user
2013-11-05T16:46:42Z
|
Reason: Not specified