In addition to the script column Jon mentions above, there's also a built-in Path Length column, which gives you the length of the full path of each file.
Sorting by that will give you the same sort order as sorting by name in most cases (since all files are usually in the same parent folder). The script column is good if you need to know the actual filename (not path) lengths and/or need to sort by them in file collections, libraries, flat view, etc.