Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the default sort option in sftp.dir.glob? #104

Open
wowremywang opened this issue Mar 22, 2020 · 1 comment
Open

What is the default sort option in sftp.dir.glob? #104

wowremywang opened this issue Mar 22, 2020 · 1 comment

Comments

@wowremywang
Copy link

I am going to sort files by modification time after getting sftp.dir.glob

Do I have to sort files manually or default sort option is modification time?

@itsalongstory
Copy link

Net::SFTP.start(@host, @user, password: @password) do |sftp|
  files = []

  sftp.dir.foreach(FILE_PATH) do |entry|
    files << { name: entry.name, mtime: entry.attributes.mtime }
  end

  files.sort_by { |file| file[:mtime] }.each do |file|
    Rails.logger.info "#{file[:name]} ---- #{file[:mtime]}"
  end
end

files.sort_by { |file| file[:mtime] } may be the way you want to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants