Substring functions

dnedrow at dnedrow at
Fri Feb 2 16:30:47 EST 2001

I'm trying to fixup someone elses work and am a complete Python neophyte.

The are two functions (is that even the term?) as follows:

def shellProtect(file):
  """Protects a filename against shell interpretation.
  This is done by putting the name in single quotes, and by
  escaping single quotes in the filename.
  return "'%s'" % string.replace(file, "'", "'\\''")

def mv(self, src, dest):
  """Shorthand for the pattern trace('mv...);os.system("mv...)."""
  self.system("mv %s %s" % (shellProtect(src), shellProtect(dest)))

Basically, mv() is called with source and destination parameters. These
are quoted via shellProtext() and then passed as input parameters for the
Unix mv command.

E.g. if src=/usr/tmp/1/* and dest=/usr/tmp/2, the mv command issued by
calling mv() above would be:

  mv '/usr/tmp/1/*' '/usr/tmp/2'

Unfortunately, a wildcard doesn't work when quoted as above. How do I
check for an * at the end of the string and quote the input as
rather than

Any pointers would be appreciated.


Sent via

More information about the Python-list mailing list