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:
How does one test to see if a directory exists from within Fastlane? Thank you for reading and for your help!
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.