Solved

Concatenation with loop and wildcard

Posted on 2003-11-04
6
546 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now