python - Getting an error when creating a new directory and moving files -


i have script that, after creating bunch of files, create new directory , move files new directory. working @ first of sudden getting error , don't know why coming up. edit: added earlier code (all in same module) wondering.

my code:

import os import shutil mydir = os.getcwd()  def edit_and_rename_files():     f = filelist() # earlier script makes list of files care     item in f:         open(item, "r+") id_file:             line in id_file:                              return my_dict # dict ids want rename          open(item, "r+") infile:             content = infile.readlines()             new_content = []             line in content: # going copy , rewrite lines                 new_line = line                 original_id, new_id in my_dict.items():                     new_line = new_line.replace(original_id, new_id + "\n")                 new_content.append(new_line)         open(item+"_renamed.fa", "w") outfile:            line in new_content:                outfile.write(line)  edit_and_rename_files()                    def move_files():     renamed_dir = mydir + "\\renamed"     if not os.path.exists(renamed_dir):         os.mkdir(renamed_dir)     else:         print "this directory exists. move files directory anyways."     root, dirs, files in os.walk(mydir):         fname in files:             if fname.endswith("_renamed.fa"):                 shutil.move(fname, renamed_dir)  move_files() 

this script executes , files created , move fine (no mistakes when open files), still error bugs me see.

traceback (most recent call last):   file "rename_concatenated_file_all.py", line 59, in <module>     move_files()   file "rename_concatenated_file_all.py", line 58, in move_files    shutil.move(fname, renamed_dir) file "c:\python27\lib\shutil.py", line 292, in move    raise error, "destination path '%s' exists" % real_dst shutil.error: destination path 'c:\users\myname\desktop\renamingwork\atp_main\renamed\atp_main_renamed.fa' exists 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -