Is there a way to iterate over all files in a folder without dropping to the os?

Answered

Comments

4 comments

  • Avatar
    alejandror

    You could use the <findFile> action, setting the tag <findAll> to 1 so it returns all the occurences, and then iterate over the list using <forEach>. Please find below an example:

    <findFile>
      <baseDirectory>/tmp</baseDirectory>
      <pattern>*.test</pattern>
      <findAll>1</findAll>
      <variable>files</variable>
    </findFile>
    <foreach variables="file">
      <values>${files}</values>
      <actionList>
          <copyFile origin="/tmp/${file}" destination="/tmp2"/>
          <changePermissions>
              <permissions>0755</permissions>
              <files>/tmp2/${file}</files>
          </changePermissions>
      </actionList>
    </foreach>
    
    0
    Comment actions Permalink
  • Avatar
    sventhegrinch

    Great... very much appreciated. Sorry I didn't see that action... makes perfect sense.

    0
    Comment actions Permalink
  • Avatar
    Klaus Triendl

    Question here: The way you present the example, I would assume only the files' names (or path relative to the base dir) will get stored into the 'files' variable.

    But according to my tests 'files' and then 'file' receive the whole path, which is a bit problematic for further file system actions - there doesn't seem to be a path manipulation action that would return the relative path or basename.

    0
    Comment actions Permalink
  • Avatar
    michiel

    You could use the <setInstallerVariableFromRegex> action to get the filename from a path:

     <setInstallerVariableFromRegEx name="fileName" text="${filePath}">
       <pattern>^(.*)[\:\/]</pattern>
    </setInstallerVariableFromRegEx>

     

    0
    Comment actions Permalink

Please sign in to leave a comment.