On Mon, Aug 25, 2008 at 3:10 PM, Tony Mechelynck
<[EMAIL PROTECTED]> wrote:
>
> 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.
fnamemodify(resolve(expand(name)), ':p')
The OP may be interested in the simplify() function since that gives a
good base for comparison.
> - 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.)
The Windows name is "junction", if I remember right, and there's no way
for Vim (or anything else for that matter) to know what other files are
hardlinked to a specific file. You can only tell whether a file is/has
hardlink by checking the link count column in the output of "ls -l" (or
any other tool which provides such information).
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---