I have a network fileshare called \\SMWEB\MSDS which contains hundreds of sub-directories named MSDSnnnn (i.e., MSDS plus a number).  Inside each sub-directory MAY be numerous files — some .html, .jpg and various .pdf files.  There may also be a sub-directory called _vti_cnf, which contains old FrontPage extensions associated with meta-data.  But there should always be at least one file within these sub-directories with the name format MSDS#.PDF.  (The number may be varying lengths; e.g., MSDS99.PDF or MSDS1099.PDF, etc.)

There may also be old, outdated versions of these files which the owner appended an X#_ in front of the file (see the red box in the image — there are two archival versions of the MSDS0001.PDF file in this example).

This is what the tree structure looks like:
        tree structure, as described

Here's what I need to accomplish: I need to copy all of the current, top-level PDF files somewhere (a single directory called SDS on my H:\ drive).  I do NOT want to replicate the sub-folders, and I only want the files with the MSDS*.PDF pattern.  (These files are highlighted in yellow in the above image.)  So I want to exclude:

  • files in sub-directories under MSDSnnnn directories (e.g., in _vti_cnf sub-directories),
  • files whose names don't begin with MSDS (e.g., the X#_ files), and
  • files whose names don't end with .PDF (e.g., HTML and JPEG files).

I tired the following command in Robocopy:

robocopy \\smweb\msds\ H:\SDS msds*.pdf /S /R:3 /W:3 /NDL /XJD /XD _vti_cnf

The problem is that Robocopy replicated the folder structure on my H: drive.

How can I accomplish my goal?

  • (1) Your image doesn’t match your text — the image shows an archived version of MSDS0002.PDF under the MSDS0001 directory. (2) What should be done with file(s) in the _vti_cnf directories? Mar 17, 2019 at 0:55
  • @Scott -- you are correct -- the archived version labeled X2_MSDS0002.PDF should have read X2_MSDS0001.PDF. The files in the _vti_cnf folders can be ignored because they are old Frontpage Extensions associated with meta-data. The files have the same name as the parent folder, but the data inside is different and should not be copied for my purposes.
    – gpence
    Mar 18, 2019 at 14:08

2 Answers 2


Have you considered using a different file copy tool? Robocopy does not support this out of the box. Here is a link that discusses that exact topic:


You can also try something simple like this

for /r \\SMWEB\MSDS %f in (MSDS*.pdf) do @copy "%f" H:\MSDS


In the end, I took a two step approach.

First I ran the Robocopy command which copied all of the files and the tree structure to a temp directory called SDS1, but it excluded the "_vti_cnf" sub-folders with the extraneous meta-data:

robocopy \\smweb\msds\ \\smf4\HOME\gpence-home\SDS1 msds*.pdf /S /R:3 /W:3 /NDL /XJD /XD _vti_cnf

Then I ran a PowerShell script which removed the sub-folders in the tree by copying the files to another directory called SDS2. (The -WhatIf parameter shows you the results without actually executing the command. Simply remove that parameter when you are ready to execute the command "for real".)

get-ChildItem -Path "\\smf4\HOME\gpence-home\SDS1\msds*.pdf" -Recurse | Copy-Item -Destination "\\smf4\HOME\gpence-home\SDS2" -WhatIf

That worked well for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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