Help please! I am new to the batch files and have a very specific question. I am trying to copy many files in multiple subdirectories into a single directory via a for loop and in the meantime attache a timestamp to each name (because all the files have the same name). I am using the system variable time and parsing it inside the loop, but the local variables inside the loop get assigned garbage. I already know about delayed expansion and using ! sign instead of %, but that doesnt help me. here is the code:
@echo off
SetLocal EnableDelayedExpansion
set counter=1
echo in the beginning the counter is "%counter%"
:loop
for /r "c:\users\wimdu\dropbox\wimdu CRM\emarsys reports - campaigns" %%f in (bounce*.*) do (
set a = %time::=%
echo in loop a equals "!a!"
echo the time is !time!
set b=!a:,=!
copy /y "%%f" c:\users\wimdu\documents\bouncehandling\bouncecsvfiles\%b%.csv
)
EndLocal
So, basically the names of the files would be 10151821.csv, for instance (time stamp including milliseconds). ideally it would be the original filename (bounces) concatenated with time stamp with .csv extension. I have tried everything but with the timestamp nothing seems to work, a just does not get assigned correctly. And then b as well . I do not know how to parse a and then assign it to b within !! signs. Please help!!
There are multiple problems.
You didn’t set “a” as you append a space, you set “a “.
And you always use the same time, as %time% will be expanded only once while parsing the block:.
The same problem you get with %b%.
Change both to delayed expansion and it could work.