def METHOD_NAME(file, odir, idirs, appx=''):
    if file.endswith('.pck'):
        try:
            haddPck( file, odir, idirs)
        except ImportError:
            pass
        return
    elif not file.endswith('.root'):
        return
    haddCmd = ['hadd']
    haddCmd.append( file.replace( idirs[0], odir ).replace('.root', appx+'.root') )
    for dir in idirs:
        haddCmd.append( file.replace( idirs[0], dir ) )
    # import pdb; pdb.set_trace()
    cmd = ' '.join(haddCmd)
    print(cmd)
    if len(cmd) > MAX_ARG_STRLEN:
        print('Command longer than maximum unix string length; dividing into 2')
        METHOD_NAME(file, odir, idirs[:len(idirs)/2], '1')
        METHOD_NAME(file.replace(idirs[0], idirs[len(idirs)/2]), odir, idirs[len(idirs)/2:], '2')
        haddCmd = ['hadd']
        haddCmd.append( file.replace( idirs[0], odir ).replace('.root', appx+'.root') )
        haddCmd.append( file.replace( idirs[0], odir ).replace('.root', '1.root') )
        haddCmd.append( file.replace( idirs[0], odir ).replace('.root', '2.root') )
        cmd = ' '.join(haddCmd)
        print('Running merge cmd:', cmd)
        os.system(cmd)
    else:
        os.system(cmd)