Search code examples
batch-filexcopy

Batch file copy from undefined directory


I am trying to copy test and test1 folder under %%e ("QA_ENDORSEMENT") since the folder name is varying.

filename QA_ENDORSEMENT sometimes varies

But I cannot get it done using my code below.

for /f "usebackq delims=" %%e in (`dir /b C:\BACKUPS\UAT`) do (
    xcopy "C:\BACKUPS\UAT\%%e\*" "C:\inetpub\wwwroot\" /F /E)

Solution

  • This will copy anything within C:\BACKUPS\UAT\*\

    So if you have C:\BACKUPS\UAT\QA_ENDORSEMENT\test it will copy test and its subdirectories and files to c:\inetpub\wwwroot but if you have C:\BACKUPS\UAT\ANOTHER\anotherfolder it will also copy anotherfolder and its sub directories to c:\inetpub\wwwroot

    for /f %%e in ('dir /b C:\BACKUPS\UAT\*') do (xcopy "C:\BACKUPS\UAT\%%e\*" "C:\inetpub\wwwroot\" /Y /F /E)
    

    Basically you will copy anything inside the subfolders of C:\BACKUPS\UAT\* but excluding the actual QA_ENDORSEMENT directory or others in UAT themselves.