I need to copy all *.doc
files (but not folders whose names match *.doc
) from a network folder \\server\source
(including files in all nested folders) to a local folder C:\destination
without preserving the nested folders hierarchy (i.e. all files should go directly into C:\destination
and no nested folders should be created in C:\destination
). In case there are several files with the same name from different subfolders of \\server\source
, only the first one should be copied and never overwritten then — all conflicting files found later should be skipped (there could be many cases like this, and the skipped files should not be trasferred over the network, otherwise it would take too much time). Here is my attempt to implement it in PowerShell:
cp \\server\source\* -Recurse -Include *.doc -Container:$false -Destination C:\destination
There are at least two problems with this command:
- It copies folders whose names match
*.doc
too. - In case of conflicting names any file found later is transferred over the network and overwrites the previous one.
Can you suggest how to fix these problems?
Implementations using copy
, xcopy
, robocopy
, cscript
or *.bat
, *.cmd
are also welcome.
The local OS is Windows 8 and the file system is NTFS.