0

I'm trying to figure out what format to use to get filereadable to recognize a file with a space in the name. This is in Ubuntu using version 7.4.1689.

The following all return 0:

filereadable('/home/user/file name')

filereadable('/home/user/file\ name')
filereadable("/home/user/file\ name")
filereadable("\/home\/user\/file\ name")
filereadable(fnameescape('/home/user/file name'))

How can I get filereadable to recognize a space in the path on Linux systems?

  • 2
    Are you really sure that /home/user/file name file exists and is readable? – mymedia Feb 24 '17 at 20:23
  • Yes, I am sure. If I remove the space from the path, it works fine. – Andrew Feb 25 '17 at 15:01
  • 3
    Generally speaking, you don't have to use escaping of file names for filereadable. And it works well for me. I've tested this with ubuntu 16.04 and vim 7.4.1683 as you did – mymedia Feb 25 '17 at 15:17
  • 3
    Like @mymedia says, filereadable() doesn't expect you to do any kind of escaping. It takes a single argument and spaces don't matter. Confirm that you're actually dealing with a space with :echo glob('/home/user/* *') and confirm that you're not actually seeing a non-breaking space with :echo glob("/home/user/*\u00a0*") – Tommy A Feb 26 '17 at 4:09
  • I'm seeing it now-- That definitely made a difference, and I'm not sure at the moment how that one got past me the first time (because I had it incorrectly listed as one that didn't work). – Andrew Feb 28 '17 at 2:29
2

filereadable('/home/user/file name') is the correct syntax.

If you want to use wildcards as well you should use glob:

if glob('~/file name')!=#""

glob returns the full name if the file exists or "" if it does not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.