If you did get rid of the spaces, and if the filenames on the server still had the spaces in them, then the code would *never* work.
Anyway, the TRIM function (no way it is a "variable") only removes spaces at the ENDs of a string, never in the middle. REPLACE() could remove all spaces, but I still question if that is the right answer.
But the big question I have: What "ListFolderContents" component? A quick google finds at least 50 or 60 separate attempts to supply one. If you don't point us to a reference to what you are using, I doubt we can help.