testing if two strings point to the same file [message #94264] |
Wed, 15 March 2017 15:43  |
MarioIncandenza
Messages: 231 Registered: February 2005
|
Senior Member |
|
|
Hello IDL Wizards,
IDL> file1='/tmp/qq/qq.dat'
IDL> file2='/tmp//qq//qq.dat'
IDL> file_copy,file1,file2
% FILE_COPY: Source file must be different from target file.
This situation will only arise if someone has done something dumb, or at least inconsistent. Let he/she who is without sin cast the first stone.
Is there a good way to test if FILE1 and FILE2 are actually the same file?
--Edward H.
|
|
|
Re: testing if two strings point to the same file [message #94265 is a reply to message #94264] |
Wed, 15 March 2017 15:56   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, March 15, 2017 at 11:43:13 PM UTC+1, Edward Hyer wrote:
> Hello IDL Wizards,
>
> IDL> file1='/tmp/qq/qq.dat'
> IDL> file2='/tmp//qq//qq.dat'
> IDL> file_copy,file1,file2
> % FILE_COPY: Source file must be different from target file.
>
> This situation will only arise if someone has done something dumb, or at least inconsistent. Let he/she who is without sin cast the first stone.
>
> Is there a good way to test if FILE1 and FILE2 are actually the same file?
>
> --Edward H.
I would try this (it works on windows):
f1_info = file_info(file1)
f2_info = file_info(file2)
if f1_info.name ne f1_info.name then file_copy,file1,file2 $
else print, 'no need to *overselfcopy*'
If you like to keep things short(er):
if (file_info(file1)).name ne (file_info(file2)).name then file_copy,file1,file2
cheers,
Helder
|
|
|
|
|
|