Batch file concatinate two files line level

January 29, 2010 at 08:14:30
Specs: Windows XP
I have a "crazy application" which dumps tiff- files into c:\ when failing.
I need to move it back to an import directory. (3 choices.)
As the tiff file has the exact same file prefix as the import xml I'm doing this semi manaully today.
123.tif search importdir, to locate 123.xml in either subdir 1,2or 3. then move tiff back.
I've been able to design two batch files. One listing the tiff's the other an output of which directory the tiffs should go back into.
file a:
file b:

I'm trying to merge these to build a move command file.
ie. move c:\123.tif d:\....

dir c:\*.tif >c:\diverse\filelist.txt /b

for /f %%i in ('type c:\diverse\filelist.txt') do call :procfile %%i

goto EOF

set filename=%1
set stripped=%filename:~0,-4%
set "stripped=dir /s /b d:\Incoming\TempImages\EhiData\%stripped%* ^>^>location.txt"
echo %stripped% >>filelist_short.cmd

goto :EOF

this generates :
move c:\004A119B2DDB4D6B83E28063A2CC32C2.TIF
move c:\d:\Incoming\TempImages\EhiData\TiffRemotePc3Inv\004A119B2DDB4D6B83E28063A2CC32C2.XML

the first line picks the the filename from input file 1 correctly. However then the loop just picks name from intput file 2.

Is there a way to get these loops to work 1 by 1?

See More: Batch file concatinate two files line level

Report •

January 30, 2010 at 00:21:59
The idea or merging files sounds interesting, but to get this done with the least fuss, try this.

]Assumes your XMLs are in one of these directories:
@echo off & setLocal EnableDELAYedeXpansion

pushd c:\

for /f "tokens=* delims= " %%a in ('dir/b *.tif') do (
for /f "tokens=* delims= " %%x in ('dir/b/s d:\pix\%%~Na.xml') do (
move %%a %%~DPx

Helping others achieve escape felicity


Report •

January 30, 2010 at 04:17:39
Seing new solutions instead of focusing deeply on problems often does the trick. This way worked great, thanks!

Report •

February 1, 2010 at 08:09:16
Here's another solution:

@echo off

REM Source dir
set sdir=C:

REM Targetdir
set tdir=d:\Incoming\TempImages\EhiData\TiffRemotePc3Inv
set tdir01=1
set tdir02=2
set tdir03=3

for /F %%F in ('dir %sdir%\*.tiff /B') do (
if exist %tdir%\%tdir01%\%%~nF.xml echo move C:\%%F %tdir%\%tdir01%
if exist %tdir%\%tdir02%\%%~nF.xml echo move C:\%%F %tdir%\%tdir02%
if exist %tdir%\%tdir03%\%%~nF.xml echo move C:\%%F %tdir%\%tdir03%

Report •
Related Solutions

Ask Question