removed trim and used substring for files with spaces