3

I am trying to copy all the files containing 'BNALP' to another directory called 'source'...I tried using the glob and shutil function to do this but an error message always arises stating "TypeError: coercing to Unicode: need string or buffer, list found". I was wondering if anyone could help me in the right direction because I am new to python.

billinkc
  • 59,250
  • 9
  • 102
  • 159
Zach
  • 31
  • 1
  • 2

1 Answers1

2

Have you tried the solutions provided on How do I copy a file in python? Based on half-remembered python and your error message, are you trying to copy a list of files to a destination? If so, you'd need to iterate through them calling the copy each time.

See also

To iterate through an enumerable object in python, you would want to use "in" Rough code lifted from unicode link above

destination = '/etc/tmp/source'
# magic here loads the list of BNALP files into a list variable
# could be something like
# files = os.listdir('/etc/BNALP')
for file in files:
    shutil.copy2(file, destination)
Community
  • 1
  • 1
billinkc
  • 59,250
  • 9
  • 102
  • 159