Solved

Concatenation with loop and wildcard

Posted on 2003-11-04
6
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Introduction to Processes

691 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