Forwarded to the list, I would also like to understand the forward slash;
os.system("mv %s/%s %s" % (src, fnames, dst))
--
Powered by Gentoo GNU/Linux
http://linuxcrazy.com
--- Begin Message ---On Tue, May 12, 2009 at 03:50:00PM -0400, David wrote: > David wrote: > > > >------------------------------------------------------------------------ > > > >Subject: > >[Tutor] simply moving files > >From: > >Matt Herzog <[email protected]> > >Date: > >Tue, 12 May 2009 13:51:36 -0400 > >To: > >Python List <[email protected]> > > > >To: > >Python List <[email protected]> > > > > > >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 resultsActually, the above does EXACTLY what I want. I hope I did not seem accusatory in my previous post. I'm just under some pressure and had become frustrated. Maybe on the weekend I'll have time to understand the line: os.system("mv %s/%s %s" % (src, fnames, dst)) Many thanks. -- Matt > > [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 -- I fear you speak upon the rack, Where men enforced do speak anything. - William Shakespeare
--- End Message ---
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
