1

I'm a newbie, a grad student, and frustrated!! I have tons of directories containing subdirectories and each subdirectory contains a bunch of .irf files (these are a DVR-type file).

I am trying to use the command prompt to get each subdirectory to contain a concatenated .irf file for the .irf's in that subdirectory. And ideally the new file would have the name of the subdirectory.

I can concatenate them no problem, going into each subfolder one by one:

copy /b *.irf concat.irf

To get this to work for each subdirectory I've been trying to use the for command and I put the copy command into a batch file (copyIRF.bat)

for /d /r %i in (*.*) do call copyIRF.bat %i )

This puts a concatenated file called concat.irf into the parent directory that is the combined files from subdirectory #1.

But then when it concats the files in the second directory it appends those to the same file concat.irf in the parent folder instead of putting the resulting files into their respective subdirectories.

What I want is:

Directory
  Subdir1
    *.irf
    *.irf
    *.irf...etc.
    Subdir1concat.irf
  Subdir2
    *.irf
    *.irf
    *.irf ...etc..
    Subdir2concat.irf

I really really appreciate any help!!

(I use Win 7 64bit pro)

1
  • If my answer was helpful, please consider marking it as accepted. See this page for an explanation of why this is important.
    – JosefZ
    Commented Jul 2, 2015 at 23:51

1 Answer 1

0

Next loop command could help:

for /F "delims=" %i in ('dir /B /S /AD') do @call copyIRF.bat "%i"

if your copyIRF.bat is defined as follows:

==>type copyIRF.bat
@echo OFF
pushd "%~1"
if exist *.irf (
    del "%~nx1concat.irf"
    copy *.irf "%~nx1concat.irf"
    echo debug copy *.irf "%~nx1concat.irf"
)
popd
exit /B

Resources (required reading):

1
  • THANK YOU SO MUCH!!! The only tweak I had to make was to add the /b to the copy command and it works brilliantly. Thanks for the resources also- now I understand what this code is doing :-)
    – Amanda
    Commented Jul 2, 2015 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .