'nested lists to make data frame using folder names

I am working with a folder that contains two layers of subfolders and the lowest level folder contains files in pdf and doc formats. I want to create a data frame where the names of the highest order folder are one column, and so on, where the text in the files is a value in the data frame. So I'd like to create something like:

States (layer 1 file names) Counties (Layer 2 file names, nested in each state name) Text

States Counties text
One A. text1
One A. text2
One B. text1

I've set the wd to the folder with all of the state names and created an object ```states <- list.dirs()````

but not sure how to nest the second layer.



Solution 1:[1]

You should look into pathlib. The Path object has a parts attribute.

See docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Speedlulu