可以't用Ruby测试Fastlane中的目录是否已经存在



我无法测试Fastlane操作或通道中是否存在目录。当前目录(运行fastlane的目录(中的save_path = "./dir_name"save_path = "dir_name"均未执行以下操作:

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

我甚至试图扩展相对路径:

File.exists? File.expand_path(save_path)

我提到了以下内容:

  1. 检查Ruby中的目录是否为空
  2. 如何检查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

如何测试Fastlane中是否存在目录?感谢您的阅读和帮助!

检查此项的正确格式:

Dir.exist? "#{save_path}" 

如果存在,将返回true;如果不存在,则返回false。

哈哈,我发现了我的问题。我没有意识到我必须包含这些语句的整个路径,因为我使用Dir.foreach来迭代文件系统的一部分;更新后的语法为:
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

这与if语句中的File.directory?("#{dir}")相反。我认为RubyDirFileUtil库在路径的其余部分看起来会相对于当前目录。

最新更新