-1

I need code for combining text files which are generated in every minutes into single file, means script run and check files generated in last 15 minutes in specific folder then combine files into single file this single file must be generated in different folder.

For Example: Current Time 15:30:00, Files Generated in C:/New as

A.TXT DateModified 20170101150150 (YYYYMMDDHHMMSS)
B.TXT DateModified 20170101151630 (YYYYMMDDHHMMSS)
C.TXT DateModified 20170101151740 (YYYYMMDDHHMMSS)
D.TXT DateModified 20170101151850 (YYYYMMDDHHMMSS)

Then: E.TXT will be generated in C:/Backup

E.TXT = B.TXT + C.TXT + D.TXT

A.TXT must not be included in E.TXT

Script required for Batch File.

:start
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set "MS=%dt:~15,3%"
set "datestamp=%YYYY%%MM%%DD%"
set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%-%MS%"

echo CurrentDate: "%datestamp%"

set SH=%Min%-15

COPY "C:\Users\hp\Desktop\New folder (2)\%datestamp%_%HH%%SH%*.txt" "C:\Users\hp\Desktop\New folder (2)\Complete_%datestamp%.txt"

TIMEOUT /T 15

GOTO start

But this copy only 2 or 3 files not all files which are generated within 15 minutes

Squashman
  • 13,649
  • 5
  • 27
  • 36
S.Manav
  • 1
  • 2
  • 1
    What have you tried, and how has what you've tried failed? Ideally, you should provide a [MCVE] of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. [SO] is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See [Ask]. – Jeff Zeitlin Oct 17 '17 at 16:36
  • Please Check the Question Again.. Thanks in Advance.. – S.Manav Oct 17 '17 at 16:44
  • just `set sh=%min%-15` isn't enough (and it's `set /a`; you can just `set /a sh=min-15`). You have to take care of underrun and then also adjust hours and take care of underrun of hours and adapt days, months and even year. Then compare each FileGeneratedDateTime to that result ([get inspired](https://stackoverflow.com/a/18024049/2152082)). – Stephan Oct 17 '17 at 18:10
  • Would it not make more sense to name `E.txt`, `A.txt`. You could of course back up or rename `A.txt` first if required. That way the frequency of running the script wouldn't be as crucial, you'd just merge all files from `B.txt` onwards, naming it `A.txt` etc. – Compo Oct 17 '17 at 22:25

1 Answers1

0

To Generate E.txt

set/p B=<B.txt
set/p C=<C.txt
set/p D=<D.txt
echo %B%>>E.txt
echo %C%>>E.txt
echo %D%>>E.txt

Output, E.txt single file with all the contents of B.txt C.txt and D.txt (A.txt will not copied)

use set /a sh=min-15 for time adjustments.

Philip
  • 409
  • 5
  • 13