Copying all files of a directory to one text file in python -


my intention copy text of c# (and later aspx) files 1 final text file, doesn't work.

for reason, "yo.txt" file not created.

i know iteration on files works, can't write data .txt file.

the variable 'data' contain text files . . .

*******could connected fact there non-ascii characters in text of c# files?

here code:

import os import sys  src_path = sys.argv[1] os.chdir(src_path)  data = "" file in os.listdir('.'):     if os.path.isfile(file):         if file.split('.')[-1]=="cs" , (len(file.split('.'))==2 or len(file.split('.'))==3):             print "copying", file             open(file, "r") f:                 data += f.read()   print data  open("yo.txt", "w") f:     f.write(data)    

if has idea, great :)

thanks

you have ensure directory file created has sufficient write permissions, if not run

  chmod -r 777 . 

to make directory writable.


Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -