[François Pinard]
import os for dir in os.listdir('.'): if dir[:5] == 'xdir_': for base in os.listdir(dir): if base[:7] == 'xfile_.': file = os.path.join(dir, base) newdir = open(file).readline()[:-len(os.linesep())] if newdir != dir: os.rename(file, os.path.join(newdir, base))
I just happened to think (under the shower :-), that if stripping surrounding whitespace to get the new directory name is acceptable, it could be use to get rid of the newline as well, yielding this script instead. Only two lines changed, the "import" line and the "newdir =" line. import os, string for dir in os.listdir('.'): if dir[:5] == 'xdir_': for base in os.listdir(dir): if base[:7] == 'xfile_.': file = os.path.join(dir, base) newdir = string.strip(open(file).readline()) if newdir != dir: os.rename(file, os.path.join(newdir, base)) -- François Pinard http://www.iro.umontreal.ca/~pinard -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/