8 Replies Latest reply on Mar 13, 2015 8:19 AM by SecretWeaponLabs

    How to explode list in an array?

    aanshi

      I have one folder in shared drive. I want to list out all file-names in that folder. I get this by using Base elements(help of below ans)

      Now I wan to save list in an array

       

      I have list of files in one variable. Now I want to explode this list by return and add it into array.

      Variable contain list of file as

      Report 13032015.pdf

      Report 12032015.pdf

      Report 11032015.pdf

      Report 10032015.pdf

       

      I wan to save it in an array so that I can do some calculation such as get date from the filename and if its 2 day old then wan to delete it

       

      How to perform this ?

       

      Message was edited by: Aanshi Gor

        • 1. Re: How to get list of files for specific folder?
          Markus Schneider

          FIleMaker supports a listing for the documents folder - get(DocumentsPathListing)

          FOr the listing of an other folder, there are plugins or system calls needed

          PLugins: MBS, Troi, BaseElements, etc

          • 2. Re: How to get list of files for specific folder?
            coherentkris

            Their are many ways to do this and not enough information in your post to make any definitive recommendations.

             

            What OS are you on?

            Do you want a recursive listing if their are nested folders or just the file list?

            How/when do you want to trigger the production of the list and what will you do in FM with the results?

            What scripting languages or other programming tools are you comfortable with or are willing to invest time in learning?

            Are you willing to invest time/money in buying a plug in or building a plug in of your own?

            • 3. Re: How to get list of files for specific folder?
              nicolai

              On a Mac the simplest solution is to use AppleScript through "perform Applescript". You can mix it with a bash command if you are more familiar with it.

               

              On a PC you can use VBS or "Send Event" and cmd to get folder listing back to FileMaker.

               

              If you use cmd or bash you will need to get folder listing back to FileMaker. I usually use clipboard, another option is to write out a text file and import it into FileMaker.

               

              As the others mentioned, this is not dynamic, you would need something to refresh your list in FileMaker when it changes. You can use User Agents on a Mac to trigger script in FileMaker to update the folder list. I am not sure if Windows has similar functionality.

               

              EDIT:

               

              While I was typing the post the original question changed completely. Safely to ignore now.

              • 4. Re: How to get list of files for specific folder?
                nicolai

                The closest thing to an array in FileMaker is repeated field, but you are better off just keeping it as a list and use getValue() to access elements. You can also use getValue() to process your list into separate records or store it in the repeated field.

                • 5. Re: How to explode list in an array?
                  coherentkris

                  Not that the question has completely changed you are asking for text parsing solutions.

                  Please look at the text functions (right, left, middle, right words, left words, middle words, etc)

                  and the list functions (valuecount, get value etc) and the repositories of custom functions available on the web and learn how to perform text parsing in FM.

                  Its one of the most valuable tools in your toolbox.

                  • 6. Re: How to get list of files for specific folder?
                    monkeybreadsoftware

                    if you use MBS Plugin, you could those functions.

                     

                    Files.List gives list of files:

                    Monkeybread Software - MBS Filemaker Plugin: Files.List

                     

                    Files.ModificationDate gives modification date:

                    Monkeybread Software - MBS Filemaker Plugin: Files.ModificationDate

                     

                    and Files.Delete can delete a file:

                    http://www.mbsplugins.eu/FilesDelete.shtml

                     

                    just 3 of 3000 documented functions in our plugin.

                    • 7. Re: How to explode list in an array?
                      siplus

                      Nicolai is right on the point here.

                       

                      You should use arrays (repeating fields) best when you know beforehand the maximum array length (how many elements) but what you have is an open ended list. No need to array it, you can move freely into it with $i ranging from 1 to ValueCount(list) and get the nth element with GetValue(list; $i).

                       

                      $deleteAfterDays = 2

                      $i = 0

                      $listLength = ValueCount(list)

                      $today = GetAsDate(Get(CurrentHostTimeStamp))

                       

                      loop

                        exit loop if (let$i = $i + 1; $i > $listLength)

                        $filename = GetValue(list; $i)

                        $cleanFileNumber = Filter($Filename;"0123456789")

                        if Length($cleanFileNumber) = 8 // poor man's error trapping, has to be improved

                          $deleteme = ($today - date(middle($cleanFileNumber);3;2);Left($cleanFileNumber;2);Right($cleanFileNumber;4)) > $deleteAfterDays)

                          if $deleteme

                             << delete the file named $filename using your preferred plugin >>

                          endif

                      endif

                      endloop

                      • 8. Re: How to explode list in an array?
                        SecretWeaponLabs

                        Save the contents of the folder to a variable. And reference each file through GetValue( $yourDocumentList ; $AndALoopCount) but if you really want to explode it, then look into key/value custom functions which will explode the values into named variables after a little manipulation.