I am writing a Win 7 batch script for copying files from various source paths to a single location. The full path names of the files being copied are listed in a text file.
The following script works when the source paths do not include spaces. I can handle spaces if path names are included into the script as constants with a combination of quotations and %~1
. How do I emulate this combination for paths being passed as parameters?
Transfer2.bat:
set SOURCELIST=c:\Temp\List1.txt
set DEST=c:\Temp\To
for /f %%A in (%SOURCELIST%) do (forfiles /p %%~dpA /s /m %%~nxA /c "cmd /c copy /y @path %DEST%\@file" 2>>log.txt)
for /f %b in (log.txt) do (echo.%~b)>>log.txt`
del log.txt
List1.txt:
C:\temp\From\Test_This Space.txt
C:\temp\From\Test.txt
Results:
Transfer is successful for C:\temp\From\Test.txt
.
Log returns
ERROR: Files of type "Test_This" not found.
forC:\temp\From\Test_This Space.txt
.