locked
get filename RRS feed

  • Question

  • If I have a string such as "D:\foldername\filename.csv"
    then how can the file name be retrieved. i.e. to get filename.csv
    Note that the path can vary and I would like to get the filename as explained.
    How is this done please?
    Thanks
    Monday, February 20, 2012 2:55 PM

Answers

  • Arkiboys,

    Try

     
    DECLARE @FILENAME1 VARCHAR(500)
    --SET @FILENAME1='C:\MANISH\TEST1.CSV' 
    SET @FILENAME1='C:\MANISH\TEST\TEST1.CSV' 
    
    SELECT REVERSE(LEFT(REVERSE(@FILENAME1),CHARINDEX('\', REVERSE(@FILENAME1),1)-1))


    Thanks
    Manish

    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Marked as answer by arkiboys Monday, February 20, 2012 3:03 PM
    Monday, February 20, 2012 3:03 PM

All replies

  • Arkiboys,

    Try

     
    DECLARE @FILENAME1 VARCHAR(500)
    --SET @FILENAME1='C:\MANISH\TEST1.CSV' 
    SET @FILENAME1='C:\MANISH\TEST\TEST1.CSV' 
    
    SELECT REVERSE(LEFT(REVERSE(@FILENAME1),CHARINDEX('\', REVERSE(@FILENAME1),1)-1))


    Thanks
    Manish

    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Marked as answer by arkiboys Monday, February 20, 2012 3:03 PM
    Monday, February 20, 2012 3:03 PM
  • Thanks
    Monday, February 20, 2012 3:03 PM