Mailinglist Archive: opensuse (2425 mails)

< Previous Next >
Re: [SLE] What application or script language?
  • From: pinard@xxxxxxxxxxxxxxxx (François Pinard)
  • Date: 13 Jun 2000 11:01:11 -0400
  • Message-id: <oq7lbtaamg.fsf@xxxxxxxxxxxxxxxxxxxxxxx>



[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@xxxxxxxx
For additional commands send e-mail to suse-linux-e-help@xxxxxxxx
Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/


< Previous Next >