Search for files with naming convention and copy it to a single directory

Hi All,

I am trying to search for files from a directory (with sub directory) for a certain file with naming convension.(ex. hostname1 , hostname2, hostname3 located to different subdirectory) and copy it to a single folder. I have tried below script but it will copy the subdirectory the file is located. Any suggestion is much appreciated.Thanks

waithidden xcopy "c:\test2\WindowsUserAudit_*.txt" /s /y "C:\Users\test\Desktop\New"

I don’t believe there is any way to iterate through all the files in a path using relevance.

I can list all the files in a folder …

files whose (name of it as lowercase starts with "hostname") of folder "C:\SomeFolder")

or list files in one folder down inside another …

files whose (name of it as lowercase starts with "hostname") of folders of folder "C:\SomeFolder")

but the second clause will not resolve files inside Sub-Sub-Folders, just like the first will not report files in Sub-Folders. I suspect this is intentional on the part of the Developers to prevent the BES Client process getting stalled looking down through a potentially enormous volume of files.

To get around this, you can use the DIR HOSTNAME*.* /B /S > Parseme.txt to list all the matching files in a folder as a text file, then use something like the following …

COPY "{Lines of File "Parseme.txt"}" "C:\SomeFolder"

Be careful how many files need to be copied and be careful how often you do it on a given machine.

You can look at all files in a folder using the descendants inspector, but generally it is a bad idea as it can be slow and problematic.