Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to: retrieve only filename when filename and path are in field

Status
Not open for further replies.

akalinowski

IS-IT--Management
Oct 3, 2006
190
US
OK, so i have a database with product information and part of it is the path to the image, they never named the image anything consistent (as in style number.jpg or product_id.jpg)
fields look like this X:\images\mens\tops\randomness.jpg X:\images\mens\pants\random.jpg
i need random.jpg and randomness.jpg only because i am moving everything to a single directory
i need to pull the file name form the database for the product image, i tried using right and charindex but it just gives me everything right of the 1st
akalinowski
 
In these circumstances, I'd use REVERSE and RIGHT
alongside CHARINDEX:

Code:
SELECT RIGHT([filelocation],(CHARINDEX('\',REVERSE([filelocation])+'\'))-1)

soi là, soi carré
 
I'd solce this on the client side, fetch the whole name and then use
-PHP: basename()
-ASP.NET, C# and VB.net: System.IO.Path.GetFileName()
-Python: os.path.basename(filePath)
-FoxPro: JustFName()
...

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top