I want to find and copy only the specific string in the file name to a different folder.

Asked 2 years ago, Updated 2 years ago, 65 views

I'm thinking about working with a batch file.
I would like to find the files in the file name test and copy only the files to the target directory (dest), although the subdirectories have different hierarchies from the current directory (target).

I would like to use robocopy to copy files because I want to skip errors and leave logs.
Thank you for your cooperation.

windows batch-file

2022-09-30 15:34

2 Answers

It's not a very neat method, but how about the following command?
Copy the subdirectory and then copy the current.

cd [FromDir]
 for /d %i in (*) docopy %i [ToDir] *test* 
 robocopy [FromDir] [ToDir] *test*


2022-09-30 15:34

If you use for in the application of the following article, you will be able to do so.
I want to extract all files in the "Designated Directory Name" in "Any Hierarchy" in "Designated Directory"

Is it like this?

 for /r TargetDir%I in (*test*.*) drobocopy% to pI DestDir% to nxI

If necessary, add detailed options such as file selection and log output to the end of the robocopy command specification.
However, if the folder name or file name contains spaces, something strange may happen, so be careful or think about it.


2022-09-30 15:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.