def expand_source_dir(source, destination, exclusions = [], destname = None, logdir = realpath(".")): """ Generate the list of copies. """ expansion = {} src_path,src_name = split(source) if destname: to_replace = source replacement = join(destination,destname) else: to_replace = src_path replacement = destination for dirname, dirs, files in walk(source): if to_replace: dest_path=dirname.replace(to_replace,replacement) else: dest_path=join(destination,dirname) # remove excluded dirs from the list dirs[:] = [ d for d in dirs if not filename_match(d,exclusions) ] # loop over files for f in files: if filename_match(f,exclusions): continue key = getRelativePath(dest_path, join(dirname,f)) value = getRelativePath(logdir, join(dest_path,f)) expansion[key] = value return expansion
def getallfiles(path,recursive): list_files=[] if(recursive==True): for root, dirs, files in walk(path): for dirname in dirs: if(dirname=="VIDEO_TS"): dirname=str(join(root,dirname).encode(stdout.encoding,'replace'))[2:-1] dirname=dirname.replace('\\\\','\\') list_files.append(dirname) for filename in files: if(filename.rsplit(".",1)[1].lower() in extensions ): filename=str(join(root,filename).encode(stdout.encoding,'replace'))[2:-1] filename=filename.replace('\\\\','\\') list_files.append(filename.replace('\\\\','\\')) else: for filename in listdir(path): if(isfile(path+'\\'+filename) and filename.rsplit(".",1)[1].lower() in extensions): filename=str(join(path,filename).encode(stdout.encoding,'replace'))[2:-1] filename=filename.replace('\\\\','\\') list_files.append(filename.replace('\\\\','\\')) return list_files