<br><br><div class="gmail_quote">On Mon, Aug 9, 2010 at 3:14 PM, blur959 <span dir="ltr"><<a href="mailto:blur959@hotmail.com">blur959@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi, all, I am working on a simple program that renames files based on<br>
the directory the user gives, the names the user searched and the<br>
names the user want to replace. However, I encounter some problems.<br>
When I try running the script, when it gets to the os.rename part,<br>
there will be an error. The error is :<br>
n = os.rename(file, file.replace(s, r))<br>
WindowsError: [Error 2] The system cannot find the file specified<br></blockquote><div><br></div><div>This is because the file does not exist.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
I attached my code below, hope you guys can help me, Thanks!<br>
<br>
import os<br>
directory = raw_input("input file directory")<br>
s = raw_input("search for name")<br>
r = raw_input("replace name")<br>
<br>
for file in os.listdir(directory):<br>
n = os.rename(file, file.replace(s, r))<br>
print n<br></blockquote><div><br></div><div>Tried this on my system, works.</div><div>>>> [shutil.move(i, r) for i in os.listdir(directory) if i==s] </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>~l0nwlf<br>