Python search and copy files in directory -


i'm new python please excuse ignorance.

i looking create way of searching 1 text file list of files conform search criteria. using results search through/recurse directory files, , copy them 1 master folder.

essentially have text file has loads of file names, have managed search through file , retrieve files ending '.mov', , print/output result text file. there may dozens of files.

how can use results recursively search through directory , copy files new location.

or, going in totally wrong way?

many thanks!

import os, shutil  # first, create list , populate files # want find (1 file per row in myfiles.txt) files_to_find = [] open('myfiles.txt') fh:     row in fh:         files_to_find.append(row.strip)  # recursively traverse through each folder # , match each file against our list of files find. root, dirs, files in os.walk('c:\\'):     _file in files:         if _file in files_to_find:             # if find it, notify , copy it c:\newpath\             print 'found file in: ' + str(root)             shutil.copy(os.path.abspath(root + '/' + _file), 'c:\\newpath\\') 

you'll never learn programmer asking "how do this" without trying find out yourself. reccomend people break prioblem down peaces..

  • google: python list files in directory
  • fiddle around example codes , see works best

then move on,

  • google: python copy file
  • fiddle around premade paths, , see if can logic work

then combine them both.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -