Problem with reject! function for array

Hello, actually I have 2 functions like that in one of my class implementation:

        def deleteFile(path : String)
            begin
                File.delete(path)
                puts path
            rescue error
                Ism.notifyOfDeleteFileError(path)
                pp error
                exit 1
            end
        end

        def deleteAllHiddenFiles(path : String)
            begin
                (Dir.children(path+"/").select! {|f| File.file? f}).each do |file|
                
                    puts path
                    puts file
                    puts file.starts_with?(".")
                    
                    if file.starts_with?(".")
                        deleteFile(path+"/"+file)
                        puts path+"/"+file
                    end
                end
            rescue error
                Ism.notifyOfDeleteAllHiddenFilesError(path)
                pp error
                exit 1
            end
        end

But strangely, when my program start to use deleteAllHiddenFiles(path : String) function, it don’t return what I expected, because it exclude the hidden file .gitignore from the list.

The path actually contain this:
zohran@zohran-VirtualBox:~/ism$ ls -la /mnt/sources/Linux-API-Headers-5.13.12/linux-5.13.12/usr/include/
total 88
drwxr-xr-x 13 zohran zohran  4096 Jun 27 19:19 .
drwxr-xr-x  3 zohran zohran  4096 Aug 18  2021 ..
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 asm
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 asm-generic
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 drm
-rw-r--r--  1 zohran zohran    44 Aug 18  2021 .gitignore
drwxr-xr-x 29 zohran zohran 36864 Jun 27 19:19 linux
drwxr-xr-x  3 zohran zohran  4096 Jun 27 19:19 misc
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 mtd
drwxr-xr-x  3 zohran zohran  4096 Jun 27 19:19 rdma
drwxr-xr-x  3 zohran zohran  4096 Jun 27 19:19 scsi
drwxr-xr-x  3 zohran zohran  4096 Jun 27 19:19 sound
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 video
drwxr-xr-x  2 zohran zohran  4096 Jun 27 19:19 xen

If I remove the select! function, I have everything, but if I use select!, in result, I have an empty array. Why ?

My goal is to keep only the list of all files and exclude all directories (before I will check if the file is an hidden file)

I think you could do what you want via like:

def delete_file(path : String)
  File.delete(path)
rescue error
  Ism.notifyOfDeleteFileError(path)
  exit 1
end

def delete_all_hidden_files(path : String)
  Dir.glob("#{path}/.*", match_hidden: true) do |file_path|
    next unless File.file? file_path

    delete_file file_path
  end
rescue error
  Ism.notifyOfDeleteAllHiddenFilesError(path)
  exit 1
end

This will iterate over all hidden files/directories, calling the delete function for each hidden file, skipping directories.

Oh thanks you ! This work better definitely !