List files from folder and subfolders recursively in JMeter











up vote
0
down vote

favorite












I use BeanShell Sampler in JMeter to list all the files from a folder. It lists files only from directory and unable to do the same in subdirectories



File folder = new File("C:\_private\Files\input");

File files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});

for (int i=0; i < files.length; i++) {
vars.put("file_" + i, files[i].getAbsolutePath());
}









share|improve this question




















  • 1




    Possible duplicate of List all files from a directory recursively with Java
    – Deepak Gunasekaran
    Nov 7 at 10:10















up vote
0
down vote

favorite












I use BeanShell Sampler in JMeter to list all the files from a folder. It lists files only from directory and unable to do the same in subdirectories



File folder = new File("C:\_private\Files\input");

File files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});

for (int i=0; i < files.length; i++) {
vars.put("file_" + i, files[i].getAbsolutePath());
}









share|improve this question




















  • 1




    Possible duplicate of List all files from a directory recursively with Java
    – Deepak Gunasekaran
    Nov 7 at 10:10













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use BeanShell Sampler in JMeter to list all the files from a folder. It lists files only from directory and unable to do the same in subdirectories



File folder = new File("C:\_private\Files\input");

File files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});

for (int i=0; i < files.length; i++) {
vars.put("file_" + i, files[i].getAbsolutePath());
}









share|improve this question















I use BeanShell Sampler in JMeter to list all the files from a folder. It lists files only from directory and unable to do the same in subdirectories



File folder = new File("C:\_private\Files\input");

File files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});

for (int i=0; i < files.length; i++) {
vars.put("file_" + i, files[i].getAbsolutePath());
}






java groovy jmeter beanshell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 11:24









user7294900

17.9k93056




17.9k93056










asked Nov 7 at 10:01









plaidshirt

56132467




56132467








  • 1




    Possible duplicate of List all files from a directory recursively with Java
    – Deepak Gunasekaran
    Nov 7 at 10:10














  • 1




    Possible duplicate of List all files from a directory recursively with Java
    – Deepak Gunasekaran
    Nov 7 at 10:10








1




1




Possible duplicate of List all files from a directory recursively with Java
– Deepak Gunasekaran
Nov 7 at 10:10




Possible duplicate of List all files from a directory recursively with Java
– Deepak Gunasekaran
Nov 7 at 10:10












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Move to use JSR223 Sampler with the following code using FileUtils:



import org.apache.commons.io.FileUtils;
List<File> files = FileUtils.listFiles(new File("C:\_private\Files\input"), null, true);


Notice to replace files.length with files.size():



for (int i=0; i < files.size(); i++) {
vars.put("file_" + i, files[i].getAbsolutePath());
}





share|improve this answer




























    up vote
    1
    down vote













    You'll need to do it recursively. You can list all the directories the same way you did for the files, and then call the function you created, recursively. When you then call the function with your initial file, it will traverse the tree structure and give you all files in a list. To add to a list use addAll.



    def listFiles(File folder) {
    ... // Recursive function
    }





    share|improve this answer




























      up vote
      1
      down vote













      Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting mainly because Groovy performance is much better comparing to other scripting options



      Groovy in its turn provides File.eachFileRecurse() function which is exactly what you're looking for.



      Example code:



      def index = 1

      new File('c:/apps/jmeter/bin').eachFileRecurse(groovy.io.FileType.FILES) {
      vars.put('file_' + index, it.getAbsolutePath())
      index++
      }





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187185%2flist-files-from-folder-and-subfolders-recursively-in-jmeter%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        Move to use JSR223 Sampler with the following code using FileUtils:



        import org.apache.commons.io.FileUtils;
        List<File> files = FileUtils.listFiles(new File("C:\_private\Files\input"), null, true);


        Notice to replace files.length with files.size():



        for (int i=0; i < files.size(); i++) {
        vars.put("file_" + i, files[i].getAbsolutePath());
        }





        share|improve this answer

























          up vote
          1
          down vote



          accepted










          Move to use JSR223 Sampler with the following code using FileUtils:



          import org.apache.commons.io.FileUtils;
          List<File> files = FileUtils.listFiles(new File("C:\_private\Files\input"), null, true);


          Notice to replace files.length with files.size():



          for (int i=0; i < files.size(); i++) {
          vars.put("file_" + i, files[i].getAbsolutePath());
          }





          share|improve this answer























            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Move to use JSR223 Sampler with the following code using FileUtils:



            import org.apache.commons.io.FileUtils;
            List<File> files = FileUtils.listFiles(new File("C:\_private\Files\input"), null, true);


            Notice to replace files.length with files.size():



            for (int i=0; i < files.size(); i++) {
            vars.put("file_" + i, files[i].getAbsolutePath());
            }





            share|improve this answer












            Move to use JSR223 Sampler with the following code using FileUtils:



            import org.apache.commons.io.FileUtils;
            List<File> files = FileUtils.listFiles(new File("C:\_private\Files\input"), null, true);


            Notice to replace files.length with files.size():



            for (int i=0; i < files.size(); i++) {
            vars.put("file_" + i, files[i].getAbsolutePath());
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 7 at 10:20









            user7294900

            17.9k93056




            17.9k93056
























                up vote
                1
                down vote













                You'll need to do it recursively. You can list all the directories the same way you did for the files, and then call the function you created, recursively. When you then call the function with your initial file, it will traverse the tree structure and give you all files in a list. To add to a list use addAll.



                def listFiles(File folder) {
                ... // Recursive function
                }





                share|improve this answer

























                  up vote
                  1
                  down vote













                  You'll need to do it recursively. You can list all the directories the same way you did for the files, and then call the function you created, recursively. When you then call the function with your initial file, it will traverse the tree structure and give you all files in a list. To add to a list use addAll.



                  def listFiles(File folder) {
                  ... // Recursive function
                  }





                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    You'll need to do it recursively. You can list all the directories the same way you did for the files, and then call the function you created, recursively. When you then call the function with your initial file, it will traverse the tree structure and give you all files in a list. To add to a list use addAll.



                    def listFiles(File folder) {
                    ... // Recursive function
                    }





                    share|improve this answer












                    You'll need to do it recursively. You can list all the directories the same way you did for the files, and then call the function you created, recursively. When you then call the function with your initial file, it will traverse the tree structure and give you all files in a list. To add to a list use addAll.



                    def listFiles(File folder) {
                    ... // Recursive function
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 7 at 10:14









                    SBylemans

                    873417




                    873417






















                        up vote
                        1
                        down vote













                        Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting mainly because Groovy performance is much better comparing to other scripting options



                        Groovy in its turn provides File.eachFileRecurse() function which is exactly what you're looking for.



                        Example code:



                        def index = 1

                        new File('c:/apps/jmeter/bin').eachFileRecurse(groovy.io.FileType.FILES) {
                        vars.put('file_' + index, it.getAbsolutePath())
                        index++
                        }





                        share|improve this answer

























                          up vote
                          1
                          down vote













                          Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting mainly because Groovy performance is much better comparing to other scripting options



                          Groovy in its turn provides File.eachFileRecurse() function which is exactly what you're looking for.



                          Example code:



                          def index = 1

                          new File('c:/apps/jmeter/bin').eachFileRecurse(groovy.io.FileType.FILES) {
                          vars.put('file_' + index, it.getAbsolutePath())
                          index++
                          }





                          share|improve this answer























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting mainly because Groovy performance is much better comparing to other scripting options



                            Groovy in its turn provides File.eachFileRecurse() function which is exactly what you're looking for.



                            Example code:



                            def index = 1

                            new File('c:/apps/jmeter/bin').eachFileRecurse(groovy.io.FileType.FILES) {
                            vars.put('file_' + index, it.getAbsolutePath())
                            index++
                            }





                            share|improve this answer












                            Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting mainly because Groovy performance is much better comparing to other scripting options



                            Groovy in its turn provides File.eachFileRecurse() function which is exactly what you're looking for.



                            Example code:



                            def index = 1

                            new File('c:/apps/jmeter/bin').eachFileRecurse(groovy.io.FileType.FILES) {
                            vars.put('file_' + index, it.getAbsolutePath())
                            index++
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 7 at 13:09









                            Dmitri T

                            66.2k33256




                            66.2k33256






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187185%2flist-files-from-folder-and-subfolders-recursively-in-jmeter%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                這個網誌中的熱門文章

                                Academy of Television Arts & Sciences

                                L'Équipe

                                1995 France bombings