Solved

Concatenation with loop and wildcard

Posted on 2003-11-04
6
555 Views
Last Modified: 2012-05-04
I need a batch file that will concatenate all files for a certain day of the form:
YYMMDDFF.001 or YYMMDDFF.txt (FF= file# <=100 and for each date string, file# is unique)
ex \\dir\03103001.001 + \\dir\03103002.txt \\dir\YYMMDD.txt
I use the following to get the necessary date format:
echo off

FOR /F "TOKENS=1-4 DELIMS=/ " %%i in ('date /t') DO (
 SET MM=%%j
 SET DD=%%k
 SET YYYY=%%l
)
SET YY=%YYYY:~2,2%
SET DATE=%YY%%MM%%DD%
rem echo %DATE%
I just need to know how to concatentate the files with a loop for filename and
a wildcard for extension.  Thanks
0
Comment
Question by:johnormond
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9681138
First, I'd mention that %DATE% is possibly a not so good choice, since newer Windows systems use it. So, maybe better assume another name, let's say THEDATE.

Then, I would try something along these lines :

@echo off
:: please adapt following line
pushd \\dir
type NUL >%THEDATE%.txt
for /f %%a in ('dir/b %THEDATE%??.*') do call :append %%a
popd
goto end

:append
ren %THEDATE%.txt %THEDATE%.tmp
copy /b %THEDATE%.tmp+%1 %THEDATE%.txt
del /q %THEDATE%.tmp
:end


Note: it would have been possible to build a copy command-line and then execute it. Problem is that from the problem statement, I can see that up to 200 files may have to fit on that command line, which can be too much for the command-line parser (supports up to something like 2000 characters only). So I think that the temporary file idea is a slower, but more reliable solution.
0
 

Author Comment

by:johnormond
ID: 9681799
I got your script and I inserted the directory in lines 3 and 5, but the file returned is empty.  Also, I should have said in my original statement that while the value of FF can be up to 99,   it  rarely goes above 5 so the copy line should work... sorry about that.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9682573
Hmm, can you please paste your script as it is now ?
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:johnormond
ID: 9682959
here it is... i renamed date to thedate as you suggested...thanks

@echo off
cls
call \\bdc\win\johnscripts\getdate2.bat


pushd \\oa\inter\
type NUL >%THEDATE%.txt
for /f %%a in ('\\oa\inter /b %THEDATE%??.*') do call :append %%a
popd
goto end

:append
ren %THEDATE%.txt %THEDATE%.tmp
copy /b %THEDATE%.tmp+%1 %THEDATE%.txt
del /q %THEDATE%.tmp
:end
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 250 total points
ID: 9682985
Ah, sorry the 'dir' in that line was actually the dir command, not a folder name.

for /f %%a in ('dir /b %THEDATE%??.*') do call :append %%a
0
 

Author Comment

by:johnormond
ID: 9683210
Thanks!!  That worked perfectly... the copy command-line method was what i was looking for but i guess this way is better, just in case i there are more files to add than anticipated...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question