def copy_media_files(from_dir, to_dir, exclude=None, dirty=False):
 for (source_dir, dirnames, filenames) in os.walk(from_dir, followlinks=True):
  relative_path = os.path.relpath(source_dir, from_dir)
  output_dir = os.path.normpath(os.path.join(to_dir, relative_path))
  exclude_patterns = [u'.*']
  exclude_patterns.extend((exclude or []))
  for pattern in exclude_patterns:
   filenames = [f for f in filenames if (not fnmatch.fnmatch(f, pattern))]
  dirnames[:] = [d for d in dirnames if (not d.startswith(u'.'))]
  for filename in filenames:
   if (not is_markdown_file(filename)):
    source_path = os.path.join(source_dir, filename)
    output_path = os.path.join(output_dir, filename)
    if (dirty and (modified_time(source_path) < modified_time(output_path))):
     continue
    copy_file(source_path, output_path)

def copy_media_files ( from_dir , to_dir , exclude = None , dirty = False ) : for ( source_dir , dirnames , filenames ) in os . walk ( from_dir , followlinks = True ) : relative_path = os . path . relpath ( source_dir , from_dir ) output_dir = os . path . normpath ( os . path . join ( to_dir , relative_path ) ) exclude_patterns = [ u'.*' ] exclude_patterns . extend ( ( exclude or [ ] ) ) for pattern in exclude_patterns : filenames = [ f for f in filenames if ( not fnmatch . fnmatch ( f , pattern ) ) ] dirnames [ : ] = [ d for d in dirnames if ( not d . startswith ( u'.' ) ) ] for filename in filenames : if ( not is_markdown_file ( filename ) ) : source_path = os . path . join ( source_dir , filename ) output_path = os . path . join ( output_dir , filename ) if ( dirty and ( modified_time ( source_path ) < modified_time ( output_path ) ) ) : continue copy_file ( source_path , output_path )
recursively copy all files except markdown and exclude[ed] files into another directory .