LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Split by \

    Employee
    Posted 11-16-2016 03:34

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ThomasT

    Hi Guys.

    I am trying to get the filename without the full path from a string. (N:\Period End Closing\2016\2016-10\Uploadfiles\MOB- Accrual TNI 10-2016 cost omp.400005047.xlsx)
    So I am trying to split by \ and picking up the last bit.
    But as you know splitting by \ is not possible.
    I have looked at several posts and "\"" was suppose to work, but it didn't?

    Any suggestions?


  • 2.  RE: Split by \

    Employee
    Posted 11-16-2016 06:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gmullin

    Hi Thomas, you could replace the \ with / and then parse it.

    node:Just_filename_no_path
    bretype:core::Filter
    editor:Label=Just filename, no path
    editor:sortkey=582c613727f2367d
    input:@40fd2c74167f1ca2/=Replace__with_.40fd2c7420761db6
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    fileparse = 'filename'.split("/")
    length = fileparse.len()
    
    emit fileparse[length-1] as Filename
    
    EOX
    editor:XY=740,220
    end:Just_filename_no_path
    
    node:Replace__with_
    bretype:core::Filter
    editor:Label=Replace \ with /
    editor:sortkey=582c610d04cf037d
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    newfile = filename.replace("\\", "/")
    
    emit newfile as filename
    
    EOX
    editor:XY=630,220
    end:Replace__with_
    
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=582c60ff0e483ff8
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    filename
    N:\Period End Closing\2016\2016-10\Uploadfiles\MOB- Accrual TNI 10-2016 cost omp.400005047.xlsx
    EOX
    editor:XY=530,220
    end:Static_Data


  • 3.  RE: Split by \

    Employee
    Posted 11-16-2016 07:21

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mlam

    Have you tried putting double slash in the split function i.e. split("\\") ?

    node:Filter
    bretype:core::Filter
    editor:sortkey=582c6a6c750a0c2b
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    
    emit 'data'.split("\\").getItem('data'.split("\\").len()-1).str() as test
    EOX
    editor:XY=180,90
    end:Filter
    
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=582c6a616c8f10f4
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    data:string
    "N:\Period End Closing\2016\2016-10\Uploadfiles\MOB- Accrual TNI 10-2016 cost omp.400005047.xlsx"
    EOX
    editor:XY=90,90
    end:Static_Data


  • 4.  RE: Split by \

    Employee
    Posted 11-16-2016 07:38

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    The \ character is used in linux as an "escape character". In your example, "\"" - you're saying that you want a double-quote character.
    Michelle and Gerry both have it right.. you want "\\" - to give you the slash itself.

    There are some other popular escape sequences:
    \n - newline
    \r - carriage return
    \" - double quote
    \\ - slash

    A couple of side notes:
    1) Many times, windows will accept the / in file names
    2) While we're on the subject, there are certain cases in which you need to send a slash out to linux as a parameter. In such a case you have to use an escaped escape, or "\\\\"


  • 5.  RE: Split by \

    Employee
    Posted 11-17-2016 01:51

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ThomasT

    Great, thank you all!