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.  test for existence of an input file?

    Employee
    Posted 09-29-2010 18:09

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

    Originally posted by: dwong80

    Is there a way to test for the existence of an input file?

    Currently, if I add an input Node e.g. Flat file into the workflow and it doesn't exist or it's empty, then the workflow stops.

    Instead, I would like to check to see if the file is empty/non-existent. If so, then go down one path of the workflow and if not, go down another path.


  • 2.  RE: test for existence of an input file?

    Employee
    Posted 09-30-2010 06:30

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

    Originally posted by: ejones

    In BrainScript there is a function named stat("filename") which returns information about the file in a list or if the file does not exist it returns a null. If the file exists, then the first item in the list is the file size. So:
    a = stat("filename")
    if a.isNull() then # the file does not exist.
    else if a[0] == 0 then # the file is empty.

    I would suggest using this function in a filter node which writes out a record only if the file exists. Then using the "Meta Check" node type to control the execution of the nodes based on the number of records received.


  • 3.  RE: test for existence of an input file?

    Employee
    Posted 09-30-2010 06:37

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

    Originally posted by: timonk

    One other way to do file checking is the Directory List node.

    You can use the Directory List node in the Core library to check a location for a specific file, or file pattern. You can then link the output of that node to a Delimited File node ( or any of the other input nodes), and load the desired file.

    Here is a simple example:

    node:Delimited_File
    bretype:core::Delimited File
    editor:sortkey=4ca48d4d198a0d20
    input:4ca48dec75107264/out1=Directory_List.40fd2c747c2b1c0a
    output:@41e6c6cd11e613c6/=
    prop:FieldDelimiter=\t
    prop:FilenameExpr=<<EOX
    'FileName'
    EOX
    prop:RecordDelimiter=\n
    editor:XY=340,120
    end:Delimited_File

    node:Directory_List
    bretype:core::Directory List
    editor:sortkey=4ca48d585cdb4ea4
    output:@40fd2c747c2b1c0a/=
    prop:DirectoryName=C:\temp
    prop:Pattern=FOO.txt
    editor:XY=210,120
    end:Directory_List