The mechanism used to determine whether two names refer to the same file depends on the operating system in use:
UNIX: Under UNIX, all files are uniquely identified by two integer values: the filesystem that contains the file and the inode number, which identifies the file within the filesystem. If the input arguments are lexically identical, FILE_SAME will return True, regardless of whether the file specified actually exists. Otherwise, FILE_SAME compares the device and inode numbers of the two files, and returns True if they are identical, or False otherwise.
Windows: Unlike UNIX, Microsoft Windows identifies files solely by their names. FILE_SAME therefore expands the two supplied paths to their fully qualified forms, converts any “8.3 short names” to their real names, and then performs a simple case insensitive string comparison to determine if the paths are identical. (See Microsoft Windows “8.3 Short Names for more information on this subject). This is reliable for local disk files, but can produce incorrect results under some circumstances:
- UNC network paths can expand to different, but equivalent, paths. For example, a network server may be referred to by either a name or an IP address.
- Network attached storage can have mechanisms for giving multiple names to the same file, but to the Windows client system the names will appear to refer to different files. For example, a UNIX server using Samba software to serve files to machines on a Windows network can use symbolic links to produce two names for the same file, but these will appear as two distinct files to a Windows machine.
For these reasons, FILE_SAME is primarily of interest on UNIX systems. Under Windows, use it only on local files.
UNIX command shells often provide the HOME environment variable to point at the user’s home directory. Many shells also expand the '~' character to point at the home directory. The following IDL statement determines if these two mechanisms refer to the same directory:
On a UNIX system, the following statement determines if the current working directory is the same as your home directory:
On some BSD-derived UNIX systems, the three commands /bin/cp, /bin/ln, and /bin/mv are actually three hard links to the same binary file. The following statement will print the number 1 if this is true on your system:
Under Mac OS X, the /etc directory is actually a symbolic link to /private/etc. As a result, the following lines of code provide a simple test to determine whether Mac OS X is the current platform:
IF FILE_SAME('/etc', '/private/etc') THEN $
PRINT, 'Running Mac OS X' ELSE $
PRINT, 'Not Running Mac OS X'
Note: The above lines are shown simply as an example; checking the value of !VERSION.OS_FAMILY is a more reliable method of determining which operating system is in use.
Result = FILE_SAME(Path1, Path2 [, /NOEXPAND_PATH] )
FILE_SAME returns True (1) if two filenames refer to the same underlying file, or False (0) otherwise. If either or both of the input arguments are arrays of file names, the result is an array, following the same rules as standard IDL operators.
Scalar or array string values containing the two file paths to be compared.
Set this keyword to cause FILE_SAME to use the Path arguments exactly as specified, without expanding any wildcard characters or environment variable names included in the paths. See FILE_SEARCH for details on path expansion. The utility of doing this depends on the operating system in use:
UNIX: Under UNIX, path expansion is not necessary unless the Path arguments use shell meta characters or environment variables.
Windows: By default, FILE_SAME expands the supplied paths to their fully qualified forms in order to be able to compare them. Preventing this path expansion cripples its ability to make a useful comparison, and is not recommended.