Skip to content

Instantly share code, notes, and snippets.

@myazdani
Created April 11, 2014 00:56
Show Gist options
  • Save myazdani/10435103 to your computer and use it in GitHub Desktop.
Save myazdani/10435103 to your computer and use it in GitHub Desktop.
file copying short cuts
import os
import shutil
def copyFromListToPath(src_paths, dest_path):
for i in range(len(src_paths)): shutil.copy2(src_paths[i], dest_path)
def getFilesWithPath(path, filetype = ""):
return [os.path.join(path,f) for f in os.listdir(path) if f.endswith(filetype)]
def getFilesFromPath(path, filetype = ""):
return [f for f in os.listdir(path) if f.endswith(filetype)]
def copyRecursiveToPath(src_path, dest_path):
filepaths = [os.path.join(root,f) for root,_,files in os.walk(src_path) for f in files if (f != '.DS_Store')]
copyFromListToPath(filepaths, dest_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment