3 Replies Latest reply on May 15, 2012 9:15 AM by kayakjunkie

    Lists, Loops

    kayakjunkie

      Title

      Lists, Loops & Variables ... Oh My!

      Post

      I'm trying to rename and move comma-delimited files preparatory to importing into FMP tables.  The file name is in the format ADYYMMDD.xxx and needs to be changed to xxxYYMMDD.CSV.

      To get the list of files, I'm using the Scriptmaster External Function ListAllFilesRecursively( Path ).

      This returns a list of paragraph separated paths in a variable.

      I need to put contents of the variable into a table.  Then loop through the records creating a new file name using Scriptmaster's MoveOrRenameFile ( originalPath ; newPath ) function.

      So how do I get the information in the variable and read it into a table?

      List_of_Files.png

        • 1. Re: Lists, Loops & Variables ... Oh My!
          philmodjunk

          Since these are in a ZIP folder, I think you'll need to decompress them before you can rename them.

          I'm also basing this post solely on what you are telling me about the external functions that use the script master plug in...

          Set variable [$PathList ; value: ListAllFilesRecursively( Path ) ]

          will load the list returned into a variable.

          you can then loop through your list of values in a loop like this:

          Loop
            Set Variable [$k ; value: $K + 1]

            put the needed script steps for what you intend to do with a single item in this list here

            Exit loop if [ $K > valueCount ( $PathList ) ]
          End Loop

          A simple way to refer to the current item in your list when setting up this loop is to use: GetValue ( $PathList ; $K )

          Thus, MoveOrRenameFile ( GetValue ( $PathList ; $K ); newPath )

          Should work, but I'm leaving it up to you to figure out what you intend to put in place of "newPath" in that script step.

          • 2. Re: Lists, Loops & Variables ... Oh My!
            kayakjunkie

            That worked out perfectly.  Here is the code I came up with to rename the files, move them up one level and delete the (now empty) folders:

            • 3. Re: Lists, Loops & Variables ... Oh My!
              kayakjunkie

              Don't know why, browser crashed while uploading image.  I highlighted the Scriptmaster Plug-In External Functions used to work with files.