11.2 Listing Existing Files
R also offers the possibility to list all files in a directory. This is particularly helpful when writing scripts that should parse over all files in a directory. Existing files are listed with the function list.files()
that outputs a character vector containing a list of files in your working director, or in any other directory provided by the optional argument path
.
Often you may not want a list of all files but just those that match a particular pattern. This is easily achieved using the argument pattern
.
11.2.1 Exercises: Listing files
See Section 18.0.27 for solutions.
- Calculate percentage of how many files in your Downloads directory are .pdf.