[Zope] Cleaning Filenames from Windows

Paul Winkler pw_lists at slinkp.com
Fri Sep 19 18:44:21 EDT 2003


On Fri, Sep 19, 2003 at 03:35:40PM -0700, Dylan Reinhardt wrote:
> On Fri, 2003-09-19 at 15:03, Edward Pollard wrote:
> > I have a form with which one can upload images.
> > 
> > However, Internet Explorer for PC is a very clever program, and instead 
> > of putting the filename in the 'filename' attribute of the request 
> > object, it puts the whole local path of the file. This of course is 
> > unsuitable for a filename on the server.
> 
> And for any remaining IE6 users who may happen to value their privacy. 
> 
> > 
> > However, due the the escape nature of the backslash, I'm having a 
> > tremendous problem writing a function to clean up this mess. I am 
> > certain I used to have a code snippit to do this, but cannot find it.
> 
> I assume you want a regex that captures everything after the final
> backslash?
> 
> How about (untested):
> 
> '.*\\([\w|\d]+)'

Or you could let the python core developers do it for you:

os.path.basename(foo)

:-)

of course, you can't import that in a Script (Python) so
it'll have to be done in an external method or Product code.
But then, the same is true of re.

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's SUPER MAN MADE OF BUTTER!
(random hero from isometric.spaceninja.com)



More information about the Zope mailing list