variables in batch file

Microsoft Windows xp professional w/serv...
March 24, 2010 at 02:03:23
Specs: Windows XP
Hi All,

Not sure if you can help me here but I am trying to write a batch file that will cross reference filenames with different file extensions and if the names match, then it will move both files. My script so far is:

cd c:\jb_test1
:echo off

fc /a c:\jb_test1\*.mxf c:\jb_test1\*.xml >nul
if errorlevel 1 goto :end
if errorlevel 0 goto :identical

:identical
move c:\jb_test1\*.mxf c:\jb_test2
move c:\jb_test1\*.xml c:\jb_test2

:END

The trouble with this is it only deals with two files at a time and is actually rendered obsolete as if the contents of the file do not match it fails anyway. There is also a requirement for the *.mxf file to be copied first and to fail if not present.

Any help greatly appreciated.



See More: variables in batch file

Report •

#1
March 24, 2010 at 04:41:43
[1] You're in the DOS forum. Are you using DOS?

[2] You will need to FC pairs and test; not a wildcard FC.

[3] if errorlevel 0 is meaningless.

[4] A pair of files, 2 different types/extensions, seem pretty unlikely to be identical. But ya never know.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
March 24, 2010 at 05:10:22
HI Mechanix,

I'm using batch command but I'm fairly new to creating these file so please forgive me if I'm in the wrong forum. I'm essentially trying to configure this for a specific workflow and there will indeed be two files, sometimes more in one directory that have the same prefix but will be either *.mxf or *.xml as this is to allow for a type of further automation. Not sure if you have any suggestions on a batch file that would do this? Again sorry if I'm in the wrong forum.


Report •

#3
March 24, 2010 at 05:37:54
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.mxf') do (
for /f "tokens=* delims= " %%i in ('dir/b *.xml') do (
  if %%~Na equ %%~Ni (
  FC %%a %%i > nul
    if not errorlevel 1 (
    echo move %%~Na.* stuff
)
)
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
March 24, 2010 at 05:41:20
Thanks Mechanix - I'll test this and see how it goes. Really appreciate your help...

Report •

#5
March 24, 2010 at 06:28:43
Hi Mechanix,

That's FANTASTIC! It works. Well done. Myself and friend have been scratching our heads about this for the last couple of days! Thanks again.


Report •

Ask Question