IT_컴퓨터_코딩_개발

[Python] unix2dos, dos2unix (파이썬 소스)

파워유저 2012. 12. 27. 14:37

import sys

import glob


 

#참고 for fname in sys.argv[1:]:


 

files = glob.glob('*.txt')

for fname in files:

    infile = open( fname, "rb" )

    instr = infile.read()

    infile.close()

    outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" ).replace( "\n", "\r\n" )   # unix2dos

    #outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" )                                     # dos2unix

    if len(outstr) == len(instr):

        continue

    

    outfile = open( fname, "wb" )

    outfile.write( outstr )

    outfile.close()