has no issue with spaces in filenames. If *.txt matches "foo bar.txt", then that's what the filename variable is set to. In the body of the loop you have to make sure you have "$filename".
You don't need play games with IFS to correctly process filesystem entry names expanded from a pattern.
You don't need play games with IFS to correctly process filesystem entry names expanded from a pattern.