Kllrnohj wrote:
Well, I'm guessing the actual problem is your code. I doubt that they actually messed up the moving and file checking routines.
So, code snippet?
I found the source of the failness.
what do you think is the output of this code:
os.path.join(*os.getcwd().split("\"))
when your current working directory is "F:\Documents\tbg"
I'll give you a hint. its not "F:\Documents\tbg"
its "F:Documents\tbg"
I didn't even realize that Windows XP allowed you to specify file paths with that syntax, I'm assuming its some sort of foul holdover from DOS? if you don't know what it means, play around on the command line a little and figure it out. Basically if my script had been run from the root of the drive it would have worked fine.
looked like this:
Code: for oldfile in extras:
newfile = "tbgbackups".join(oldfile.split("thebuildersgame"))
#print "O: %s N: %s" % (oldfile,newfile)
if not(os.path.exists(oldfile)):
print "wtf: %s is missing" % oldfile
raw_input()
#print os.path.exists(newfile)
dirs = newfile.split("\\")[:-1]
dirs.reverse()
curdir = ""
while dirs:
#print curdir
#print dirs
ndir = dirs.pop()
#print ndir
curdir = os.path.abspath(os.path.join(curdir,ndir))
#print curdir
#print ""
print os.path.exists(os.path.abspath(curdir))
#print os.path.abspath(curdir)
if not os.path.exists(curdir):
os.mkdir(curdir)
#print "blah"
#print os.path.isdir(curdir)
#else:
print "meh"
print curdir
#print os.path.isdir(curdir)
print ""
try:
shutil.move(oldfile, newfile)
except IOError, (errno, strerror):
print "I/O error(%s): %s" % (errno, strerror)
os.path.exists() would say "OH YES, THAT DIRECTORY EXISTS" (same with os.path.isdir())
but then shutil.move() would say "OH NO IT DOESN'T BETCH, GET BACK IN LINE"
after 30 minutes of various debugging attempts I discovered the problem, and changed it to this:
Code:
for oldfile in extras:
newfile = "tbgbackups".join(oldfile.split("tbg"))
#print "O: %s N: %s" % (oldfile,newfile)
if not(os.path.exists(oldfile)):
print "wtf: %s is missing" % oldfile
raw_input()
#print os.path.exists(newfile)
dirs = newfile.split("\\")[1:-1]
dirs.reverse()
curdir = "F:\\"
while dirs:
#print curdir
#print dirs
ndir = dirs.pop()
#print ndir
curdir = os.path.abspath(os.path.join(curdir,ndir))
#print curdir
#print ""
print os.path.exists(os.path.abspath(curdir))
#print os.path.abspath(curdir)
if not os.path.exists(curdir):
os.mkdir(curdir)
#print "blah"
#print os.path.isdir(curdir)
#else:
print "meh"
print curdir
#print os.path.isdir(curdir)
print ""
try:
shutil.move(oldfile, newfile)
except IOError, (errno, strerror):
print "I/O error(%s): %s" % (errno, strerror)
shutil.move() still didn't move the files, it just copied them over, which kind of defeated the purpose of the whole experiment. I ended up writing *another* script to delete any file from the main tbg folder that was also in the backup directory.
[edit]
also, if you don't know who/what ActiveState is or haven't been on the ASPN hasn't spent nearly enough time programming real applications in Python.
http://mail.python.org/pipermail/python-list/2007-July/447987.html