CK5
CK5

Reputation: 1195

How to copy a file to a windows path with wildcards in it?

I am newbie to windows os. Please pardon my question if you feel it is like a noob question.

I am trying to copy a a file from one path to another path. The thing is that the destination path has a wildcard character in it. How to copy? I assumed it as a simple task, but not to be.

This is the command

copy *.zip "C:\MyCave\iso\SDG\cmpdir\copy test\ab\cd\*\gh"

The folder after ab\cd is dynamic. So I have tried to use wildcard, but this is throwing an error.

The filename, directory name, or volume label syntax is incorrect.
        0 file(s) copied.

I want to copy files in directory gh in the path.

How to do it?

Regards

Upvotes: 0

Views: 1316

Answers (1)

Compo
Compo

Reputation: 38719

I would offer this method.

For /D %G In ("C:\MyCave\iso\SDG\cmpdir\copy test\ab\cd\*") Do @For %H In ("%G\gh") Do @If "%~aH" GEq "d" Copy /Y "*.zip" "%~H" 1>NUL

To begin to understand what the command does, please open a Command Prompt window, type for /?, press the ENTER key, and read the information presented. You should do the same using If /? and Copy /? too.

The first part, For /D %G In ("FilePath\*") will return as %G directories located in FilePath. (Each of those will be your dynamic/unknown directory names).

The next part uses another loop to test each of those unknown directories, with your known directory names appended to it. The results from that loop, returned as %H, are then checked for the directory attribute, and if true, the copy command is performed using it.

Please note, that if there are more than one dynamic directory names containing a subdirectory named gh, your .zip files will be copied to each of them.

Upvotes: 1

Related Questions