copy file to folder in known location but random name

708 views Asked by At

I need to move one configuration file to somewhere else, The thing is that I don't know the name of the parent folder that I want to move it to because the name is being created randomly.

 sourcefolder                           destinationfolder
          |                              |    |StaticFolder
          |                              |        | AnotherStaticFolder 
          |                              |           | Randomfolder
          |                                              | StaticFolder
          \cofiguration.conf                                  \cofiguration.conf

How can I do it this with xcopy or any batch command?

1

There are 1 answers

2
Compo On BEST ANSWER

What about just doing:

@for /d %%a in ("C:\destinationfolder\StaticFolder\AnotherStaticFolder\temp*") do @copy "C:\sourcefolder\configuration.conf" "%%a"

This assumes there will be only one folder beginning with temp in the random folder name location.

[Edit /]

With the change that you've now added you should still be able to utilise the same base code and just add an extra if layer:

@for /d %%a in ("C:\destinationfolder\StaticFolder\AnotherStaticFolder\temp*"
) do @if exist "%%a\StaticFolder\" (
        @copy "C:\sourcefolder\configuration.conf" "%%a\StaticFolder")