Solved

Concatenation with loop and wildcard

Posted on 2003-11-04
6
551 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
3 Use Cases for Connected Systems

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

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

810 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