I want a list of all files which are in various subfolders. Since subfolders are constantly added I need to update the list of subfolders automatically.
For the example I have added the subfolders html,pdf,md
.
#!/bin/zsh
# I get all the subfolders of the folder DIR automatically as a list.
folder=$(ls -l DIR/ | awk '/^d/ { print $9 }' | tr '\n' ',' | sed 's/,$//g' )
echo "Folder: $folder"
# --> html,md,pdf
# Now get the files of the found subfolders
files=$(ls -m DIR/{$folder}/*)
echo "Files: $files"
# DOES NOT WORK
# this works instead:
ls -m DIR/{html,md,pdf}/*
Putting in the subfolder’s names manually in the ls
-command works fine.
The output I am hoping to get back from $files
is (example):
DIR/html/dataStorage.html, DIR/md/dataStorage.md, DIR/pdf/data.pdf, DIR/pdf/dataStorage.pdf
I am using zsh
.