A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRGet the list the files in a Directory/Folder to a dataset

Introduction

  • A common utility task: read the list of files in a folder into a dataset so we can loop over them, filter by extension, or join against an expected-file manifest.
  • We want columns like full_filename (path + name), filename (name only), basename (name without extension), and extension.
  • SAS uses the filesystem functions dopen(), dnum(), dread(), and dclose() to walk a directory, plus scan() and substr() to split the name and extension.
  • Tidyverse uses list.files() plus the tools package helpers file_path_sans_ext() and file_ext().
  • Base R uses the same list.files() and tools helpers — no extra package required.
  • This lesson builds the file-list data frame for a local folder and derives the basename and extension for each entry.

Get the list the files in a Directory/Folder to a dataset