The for /R loop always returns absolute paths, even if the (optional) given root directory behind /R is relative.
A possible way to get relative paths is to (mis-)use the xcopy command together with its /L option that prevents anything to be copied:
xcopy /L /S /I ".\*.*" "%TEMP%"
To remove the summary line # File(s) apply a filter using find using a pipe:
xcopy /L /S /I ".\*.*" "%TEMP%" | find ".\"
To process the returned items use a for /F loop:
for /F "eol=| delims=" %%F in (' xcopy /L /S /I ".\*.*" "%TEMP%" ^| find ".\" ') do ( echo Processing file "%%F"... )
If you just want to copy files including the sub-directory structure you do not even need the above stuff with for loops, you can simply use xcopy:
xcopy /S /I "D:\Source\*.*" "D:\Destination"
or robocopy:
robocopy /S "D:\Source" "D:\Destination" "*.*"
forloop or relative paths. I you open up a Command Prompt window and enter bothxcopy /?androbocooy /?, read through their usage information and choose whichever of them you wish, it may be sufficient for your needs.Robocopyis the newer, and was built to supercedexcopy, so I'd recommend that if you're unsure.