Copying subfolders to another drive within FOR loop

Assume I have a directory structure as follows:

D:\TEST\IMGS (2012)

D:\TEST\IMGS 2012

D:\TEST\IMGS (2013)

D:\TEST\IMGS 2013

Each IMGS subfolder has file content. Why on earth does my batch script below not just copy the folders which have parentheses to C:\TEST? Instead it copies the files within a folder with parentheses.

@echo off

setlocal enabledelayedexpansion

for /d %%i in (D:\TEST\*(*) do (
    set folder=%%i
    echo !folder!
    pause
    xcopy "%%i" "C:\TEST" /i /s
)
pause




  • Edited by CMJR1979 Tuesday, March 31, 2015 1:34 AM
March 31st, 2015 1:24am

Nevermind... I changed the destination directory to this: "C:\%%~pni" now it works.
  • Marked as answer by CMJR1979 Tuesday, March 31, 2015 6:23 AM
  • Unmarked as answer by CMJR1979 Tuesday, March 31, 2015 6:23 AM
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 3:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics