Gossamer Forum
Home : General : Perl Programming :

Removing the path to the image....

Quote Reply
Removing the path to the image....
How would I do this?

I have the following entries in a database:

c:\winnt\profiles\administator\123.gif
c:\abc.gif
d:\winnt\alpha.gif

How would I make those entries look like:

123.gif
abc.gif
alpha.gif

I want to get rid of everything from the last / to the beginning (right to left). Any ideas?

Thanks,
Nicholas

------------------
Quote Reply
Re: Removing the path to the image.... In reply to
Use this:

Code:
#!/usr/local/bin/perl

$image_path = "c:/testing/test.gif";
print "Content-type: text/html\n\n";
print $1 if $image_path =~ /.*\.([^.]*\.[^.]*)/;
Quote Reply
Re: Removing the path to the image.... In reply to
That doesn't work. First of all, the database format is:

c:\blah\blah.gif, not:
c:/blah/blah.gif

Secondly, I need the routine to work regardless of how many /(s) there are. So that:

c:\123.gif
and
c:\winnt\123.gif

would be 123.gif

Anyideas?

thanks, Nicholas

------------------
Quote Reply
Re: Removing the path to the image.... In reply to
Ok. Basicall, I have everything working. I need to know how to do one thing though. How would I change all the backslashes in a file name to double back slashes?

For example, change this:

C:\windows\abc.gif

to:

c:\\windows\\abc.gif

Thannks.

[This message has been edited by CEGlobe (edited May 16, 1999).]
Quote Reply
Re: Removing the path to the image.... In reply to
Then try this:
Code:
#!/usr/local/bin/perl
$image_path = "c:\testing\test.gif";
print "Content-type: text/html\n\n";
print $1 if $image_path =~ /.*\([^\]*\.[^\]*)/;

It checks fot the last dot, and then reads back till the \ before!
Quote Reply
Re: Removing the path to the image.... In reply to
To change all backslashes to double backslashes (if this is for perl, I would just use forward slashes, it understands):

$file =~ s/\\/\\\\/g;

should do the trick.

Cheers,

Alex