David wrote:
------------------------------------------------------------------------ Subject: [Tutor] simply moving files From: Matt Herzog <m...@blisses.org> Date: Tue, 12 May 2009 13:51:36 -0400 To: Python List <tutor@python.org> To: Python List <tutor@python.org> On monday I posted the below code: def schmove(src,dst): ... src = '/home/datasvcs/PIG/cjomeda_exp/' ... dst = '/home/datasvcs/PIG/cjomeda_exp_archive/' ... listOfFiles = os.listdir(src) ... for filez in listOfFiles: ... os.system("mv"+ " " + src + " " + dst) David Angel replied to my post and I guess I accidentally deleted his response. Today I found his response posted on mail-archive.com and tried some variations. They all failed. David said, "Just use os.rename() if the dest is a directory, it'll move the file there." Example: If I use: "os.rename(src, dst)" where I had "os.system("mv"+ " " + src + " " + dst)" no files are coppied. os.renames happily renames the source directory, but that's not what I want. Any other suggestions? -- Matt
I did not try Davids example but Kents works fine here; #!/usr/bin/python #Python 2.6.2 import os src = '/home/david/test_src/' dst = '/home/david/test/' listofFiles = os.listdir(src) for fnames in listofFiles: os.system("mv %s/%s %s" % (src, fnames, dst)) results = os.listdir(dst) print results [results] david [03:37 PM] opteron ~ $ ./tutor_mv.py ['fruit_loops.py', 'numberList.py', 'sumList.py'] david [03:42 PM] opteron ~ $ ls /home/david/test fruit_loops.py numberList.py sumList.py -- Powered by Gentoo GNU/Linux http://linuxcrazy.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor