SET "filename1=alreadydone.txt"
IF NOT EXIST "%filename1%" ECHO x:>>"%filename1%"
FOR /f "delims=" %%a IN (
'dir /b /a-d /o:d "*.csv" ^|findstr /x /v /g:"%filename1%'
) DO (
rem do your combine-file [%%a] here
ECHO %%a>>"%filename1%"
)
This part-routine (generating %%a
instead of %%F
because that's what my template does) takes the directory list and excludes files in filename1
. The remaining files are delivered to the combine-file section of the code you've already produced, and the filename is recorded in filename1
.
The if not exist
line generates a dummy entry in filename1
so that findstr
does not complain the file is empty.
With this scheme, once any file has been processed, its name is saved in filename1
and it won't be re-processed. Only new files will be combined using your combination code.
Result: No anchor about "7" or any other number of days. If you run it 7 days apart, those 7 days' processing will be combined and recorded. If you do it 5 days apart in anticipation of a public holiday, it will combine those 5 days. If you go on vacation for 2 weeks, then since no-one will follow your instruction to run it, it will combine the last 14 days. Or you could run it every day...
So here's the combined batch
@echo off
setlocal
set first=1
set fileName="combinedFiles.csv"
SET "filename1=alreadydone.txt"
IF NOT EXIST "%filename1%" ECHO x:>>"%filename1%"
>%fileName% (
for /f %%F in ('dir /b /a-d /o:d "*.csv" ^|findstr /x /v /g:"%filename1%"'
) do (
ECHO %%F>>"%filename1%"
if not "%%F"==%fileName% (
if defined first (
type "%%F"
set "first="
) else more +1 "%%F"
)
)
)
[Edit:] removed sourcedir
in for/f
because no directory-specification is required (files are in current directory)
[Further edit:] re-add /f
in for
and add missing closing-rabbit's ears.