Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get names of all files from a folder with Ruby

I want to get all file names from a folder using Ruby.

like image 807
Željko Filipin Avatar asked Nov 18 '09 12:11

Željko Filipin


People also ask

How do I get a list of files in a directory and subfolders?

Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.

How do I list all files in a directory in R?

To list all files in a directory in R programming language we use list. files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories.

How do you create a directory in ruby?

Using Ruby's Mkdir Method To Create A New Directory If you want to create a new folder with Ruby you can use the Dir. mkdir method. If given a relative path, this directory is created under the current path ( Dir. pwd ).


1 Answers

You also have the shortcut option of

Dir["/path/to/search/*"] 

and if you want to find all Ruby files in any folder or sub-folder:

Dir["/path/to/search/**/*.rb"] 
like image 159
Ian Eccles Avatar answered Nov 10 '22 09:11

Ian Eccles