On 25/08/08 15:14, Jürgen Krämer wrote:
>
> Hi,
>
> Robert Webb wrote:
>> Another simple question:
>>
>> In a vim script, how do I compare two file names to see if they are the same
>> file?  They may be relative or absolute paths.
>>
>> Obviously if I can expand both to a full path then the comparison is easy,
>> but expand("path/file:p") doesn't do it.  ":p" only works after "%" etc.
>
> use fnamemodify() instead of expand().
>
> Regards,
> Jürgen
>

Yes, except that:

- there are also circumstances where expand() will expand and 
fnamemodify() won't, e.g. when there is a $NAME for an environment 
variable in the pathname. This can (I think) be cured by using 
fnamemodify(expand(name),':p')

- On systems where soft links are possible (including most flavours of 
Unix/Linux), they won't be followed. I don't know how to obtain the full 
pathname after following any symlinks. Vim has the potential to do it 
(it will e.g. detect that a swapfile exists for a file even when trying 
to open a symlink to it) but I don't know if this capability is 
accessible to Vim scripts.

- On systems where hard links are possible (including not only 
Unix/Linux, but also, IIUC, NTFS filesystems on Windows NT and later) a 
file may have more than one name (more than one directory entry, 
possibly in different directories but not different drives or 
partitions, can legally point to the same area on the disk). This case 
is rarer than the symlink case but it may exist, at least in theory; I 
don't even know whether Vim is able to detect the condition. ("Hard 
link" is the Unix name; the Windows name is different -- I don't know it 
-- but the phenomenon is the same.)


Best regards,
Tony.
-- 
My God, I'm depressed!  Here I am, a computer with a mind a thousand
times as powerful as yours, doing nothing but cranking out fortunes and
sending mail about softball games.  And I've got this pain right
through my ALU.  I've asked for it to be replaced, but nobody ever
listens.  I think it would be better for us both if you were to just
log out again.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui