Scenario :
A folder in Linux system. I want to loop through every .xls file in a folder.
This folder typically consists of various folders, various filetypes
bash:
for f in *.xls ; do xls2csv "$f" "${f%.xls}.csv" ; done
Look at the find command.
What you are looking for is something like
find . -name "*.xls" -type f -exec program
Post edit
find . -name "*.xls" -type f -exec xls2csv '{}' '{}'.csv;
will execute xls2csv file.xls file.xls.csv
Closer to what you want.
find . -type f -name "*.xls" -printf "xls2csv %p %p.csv\n" | bash
bash 4 (recursive)
shopt -s globstar
for xls in /path/**/*.xls
do
xls2csv "$xls" "${xls%.xls}.csv"
done
for i in *.xls ; do
[[ -f "$i" ]] || continue
xls2csv "$i" "${i%.xls}.csv"
done
The first line in the do
checks if the "matching" file really exists, because in case nothing matches in your for
, the do
will be executed with "*.xls" as $i
. This could be horrible for your xls2csv
.