Can't test if directory already exists from within Fastlane with Ruby











up vote
0
down vote

favorite












I can’t test whether a directory exists from within a Fastlane action nor lane. None of the following work for save_path = "./dir_name" nor save_path = "dir_name" in the current directory (from which fastlane is being run):



!Dir.empty?(save_path)
!Dir[save_path].empty?
Dir.exist?(save_path)
File.exist?(save_path)
File.directory?(save_path)


I even tried to expand the relative path:



File.exists? File.expand_path(save_path)



I have referred to the following:




  1. Check if directory is empty in Ruby

  2. How to check if a given directory exists in Ruby

  3. https://blog.bigbinary.com/2017/02/28/dir-emtpy-included-in-ruby-2-4.html

  4. https://ruby-doc.org/core-2.2.0/Dir.html


How does one test to see if a directory exists from within Fastlane? Thank you for reading and for your help!










share|improve this question


























    up vote
    0
    down vote

    favorite












    I can’t test whether a directory exists from within a Fastlane action nor lane. None of the following work for save_path = "./dir_name" nor save_path = "dir_name" in the current directory (from which fastlane is being run):



    !Dir.empty?(save_path)
    !Dir[save_path].empty?
    Dir.exist?(save_path)
    File.exist?(save_path)
    File.directory?(save_path)


    I even tried to expand the relative path:



    File.exists? File.expand_path(save_path)



    I have referred to the following:




    1. Check if directory is empty in Ruby

    2. How to check if a given directory exists in Ruby

    3. https://blog.bigbinary.com/2017/02/28/dir-emtpy-included-in-ruby-2-4.html

    4. https://ruby-doc.org/core-2.2.0/Dir.html


    How does one test to see if a directory exists from within Fastlane? Thank you for reading and for your help!










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I can’t test whether a directory exists from within a Fastlane action nor lane. None of the following work for save_path = "./dir_name" nor save_path = "dir_name" in the current directory (from which fastlane is being run):



      !Dir.empty?(save_path)
      !Dir[save_path].empty?
      Dir.exist?(save_path)
      File.exist?(save_path)
      File.directory?(save_path)


      I even tried to expand the relative path:



      File.exists? File.expand_path(save_path)



      I have referred to the following:




      1. Check if directory is empty in Ruby

      2. How to check if a given directory exists in Ruby

      3. https://blog.bigbinary.com/2017/02/28/dir-emtpy-included-in-ruby-2-4.html

      4. https://ruby-doc.org/core-2.2.0/Dir.html


      How does one test to see if a directory exists from within Fastlane? Thank you for reading and for your help!










      share|improve this question













      I can’t test whether a directory exists from within a Fastlane action nor lane. None of the following work for save_path = "./dir_name" nor save_path = "dir_name" in the current directory (from which fastlane is being run):



      !Dir.empty?(save_path)
      !Dir[save_path].empty?
      Dir.exist?(save_path)
      File.exist?(save_path)
      File.directory?(save_path)


      I even tried to expand the relative path:



      File.exists? File.expand_path(save_path)



      I have referred to the following:




      1. Check if directory is empty in Ruby

      2. How to check if a given directory exists in Ruby

      3. https://blog.bigbinary.com/2017/02/28/dir-emtpy-included-in-ruby-2-4.html

      4. https://ruby-doc.org/core-2.2.0/Dir.html


      How does one test to see if a directory exists from within Fastlane? Thank you for reading and for your help!







      fastlane fileutils ruby-2.5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 3:25









      Wanda B.

      417




      417
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          The correct format to check this:



          Dir.exist? "#{save_path}" 


          Will return true if it exists or false if not.






          share|improve this answer





















          • Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
            – Wanda B.
            Nov 9 at 17:42










          • Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
            – rcarba
            Nov 12 at 8:20


















          up vote
          0
          down vote













          LOL Well, I discovered my issue. I didn't realize that I had to include the entire path to each of these statements, since I'm using Dir.foreach to iterate over part of the filesystem; the updated syntax is:



          Dir.foreach(save_path) do |dir|
          next if dir == '.' or dir == '..'
          if (File.directory?("#{save_path}#{dir}"))
          begin
          FileUtils.mkdir_p("./#{save_path}#{dir}/images")
          rescue StandardError => e
          UI.message("Failed to make directory ./#{save_path}#{dir}/images: #{e.to_s}")
          return
          end
          end
          end


          This is versus File.directory?("#{dir}") in that if statement. I thought that the Ruby Dir and FileUtil libraries would look relative to the current directory for the remainder of the path.






          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%2f53219419%2fcant-test-if-directory-already-exists-from-within-fastlane-with-ruby%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            The correct format to check this:



            Dir.exist? "#{save_path}" 


            Will return true if it exists or false if not.






            share|improve this answer





















            • Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
              – Wanda B.
              Nov 9 at 17:42










            • Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
              – rcarba
              Nov 12 at 8:20















            up vote
            0
            down vote













            The correct format to check this:



            Dir.exist? "#{save_path}" 


            Will return true if it exists or false if not.






            share|improve this answer





















            • Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
              – Wanda B.
              Nov 9 at 17:42










            • Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
              – rcarba
              Nov 12 at 8:20













            up vote
            0
            down vote










            up vote
            0
            down vote









            The correct format to check this:



            Dir.exist? "#{save_path}" 


            Will return true if it exists or false if not.






            share|improve this answer












            The correct format to check this:



            Dir.exist? "#{save_path}" 


            Will return true if it exists or false if not.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 9 at 12:50









            rcarba

            716




            716












            • Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
              – Wanda B.
              Nov 9 at 17:42










            • Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
              – rcarba
              Nov 12 at 8:20


















            • Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
              – Wanda B.
              Nov 9 at 17:42










            • Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
              – rcarba
              Nov 12 at 8:20
















            Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
            – Wanda B.
            Nov 9 at 17:42




            Thanks for your reply! Isn't this syntax equivalent to Dir.exist?(save_path), as specified above? I appreciate your insight!
            – Wanda B.
            Nov 9 at 17:42












            Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
            – rcarba
            Nov 12 at 8:20




            Yes, you're right, I didn't see that you write it also that way. Glad you found the solution anyway!
            – rcarba
            Nov 12 at 8:20












            up vote
            0
            down vote













            LOL Well, I discovered my issue. I didn't realize that I had to include the entire path to each of these statements, since I'm using Dir.foreach to iterate over part of the filesystem; the updated syntax is:



            Dir.foreach(save_path) do |dir|
            next if dir == '.' or dir == '..'
            if (File.directory?("#{save_path}#{dir}"))
            begin
            FileUtils.mkdir_p("./#{save_path}#{dir}/images")
            rescue StandardError => e
            UI.message("Failed to make directory ./#{save_path}#{dir}/images: #{e.to_s}")
            return
            end
            end
            end


            This is versus File.directory?("#{dir}") in that if statement. I thought that the Ruby Dir and FileUtil libraries would look relative to the current directory for the remainder of the path.






            share|improve this answer

























              up vote
              0
              down vote













              LOL Well, I discovered my issue. I didn't realize that I had to include the entire path to each of these statements, since I'm using Dir.foreach to iterate over part of the filesystem; the updated syntax is:



              Dir.foreach(save_path) do |dir|
              next if dir == '.' or dir == '..'
              if (File.directory?("#{save_path}#{dir}"))
              begin
              FileUtils.mkdir_p("./#{save_path}#{dir}/images")
              rescue StandardError => e
              UI.message("Failed to make directory ./#{save_path}#{dir}/images: #{e.to_s}")
              return
              end
              end
              end


              This is versus File.directory?("#{dir}") in that if statement. I thought that the Ruby Dir and FileUtil libraries would look relative to the current directory for the remainder of the path.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                LOL Well, I discovered my issue. I didn't realize that I had to include the entire path to each of these statements, since I'm using Dir.foreach to iterate over part of the filesystem; the updated syntax is:



                Dir.foreach(save_path) do |dir|
                next if dir == '.' or dir == '..'
                if (File.directory?("#{save_path}#{dir}"))
                begin
                FileUtils.mkdir_p("./#{save_path}#{dir}/images")
                rescue StandardError => e
                UI.message("Failed to make directory ./#{save_path}#{dir}/images: #{e.to_s}")
                return
                end
                end
                end


                This is versus File.directory?("#{dir}") in that if statement. I thought that the Ruby Dir and FileUtil libraries would look relative to the current directory for the remainder of the path.






                share|improve this answer












                LOL Well, I discovered my issue. I didn't realize that I had to include the entire path to each of these statements, since I'm using Dir.foreach to iterate over part of the filesystem; the updated syntax is:



                Dir.foreach(save_path) do |dir|
                next if dir == '.' or dir == '..'
                if (File.directory?("#{save_path}#{dir}"))
                begin
                FileUtils.mkdir_p("./#{save_path}#{dir}/images")
                rescue StandardError => e
                UI.message("Failed to make directory ./#{save_path}#{dir}/images: #{e.to_s}")
                return
                end
                end
                end


                This is versus File.directory?("#{dir}") in that if statement. I thought that the Ruby Dir and FileUtil libraries would look relative to the current directory for the remainder of the path.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 20:00









                Wanda B.

                417




                417






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219419%2fcant-test-if-directory-already-exists-from-within-fastlane-with-ruby%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







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word