How to check if file from sftp server already exists in database

Options

Hi! I'm trying to make a task in which I call an sftp server and check for new files in a path. I'm sending an external api request to list all the files in that path and getting their filename by creating a variable. How do I then use that variable (the filename) to check whether that file already exists in my database? 

Tagged:

Best Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Answer ✓
    Options

    hey @chrstnstl - the file name is part of the metadata that is stored in the database. You can check for Existence with a Has Record function based on the field.name.. for example, mine field is called "pic" so pic.name is the filename


  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited February 2023 Answer ✓
    Options

    @chrstnstl assuming you have a text file:

    1) Read the file into memory by using "get file data from resource"

    2) Split the file based on the newline character

    3) Create a variable that is based on the split data and apply a filter to "get" the first item in the array (e.g. path 0)

    4) Create a variable that is based on the split data and apply a filter to "get the last item in the array (e.g. path of the count of the array minus one)

    Manipulating files is one of those hard problems we work on in our daily State Change Pro office hours.

Answers