确定两个文件是否相同 [英] Deciding whether two files are the same

查看:58
本文介绍了确定两个文件是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个程序将两个文件作为其命令

行参数。是否有(跨平台)方式来判断

两个文件是否相同?简单的字符串比较是不够的,因为

两个文件可能被指定为file.txt。和./ file.txt,或者其中一个

它们可能是另一个的符号链接。


[我已经发布了这个30分钟前,但它没有出现在谷歌

团体---抱歉,如果有人得到它两次。]

解决方案

SzH写道:


假设有一个程序将两个文件作为其命令

行参数。是否有(跨平台)方式来判断

两个文件是否相同?简单的字符串比较是不够的,因为

两个文件可能被指定为file.txt。和./ file.txt,或

之一,它们可能是另一个的符号链接。



两个文件相同是什么意思?相同的内容?

相同的尺寸?相同的类型?同名?相同的部分路径?

同一个拥有者?相同的权限?没有定义

相同在C ++之外的相同对象当谈到什么指针

点。 *您*需要定义相同当涉及到文件时。


V

-

请删除资金''A'时通过电子邮件回复

我没有回复最热门的回复,请不要问


我猜SzH意味着路径。

我有同样的问题。在.NET中有这样的东西

Framework(Path.Equals)

但我在Win32 API或任何标准库中都找不到:(

1月24日上午9:27,Victor Bazarov< v.Abaza ... @ comAcast.netwrote:


SzH写道:


假设有一个程序将两个文件作为其命令

行参数。是否有(跨平台) )判断

两个文件是否相同的方法?简单的字符串比较是不够的,因为

两个文件可能被指定为file.txt和 ; ./ file.txt或其中一个

它们可能是另一个的符号链接。



对于两个是什么意思文件是相同?相同的内容?

相同的大小?相同的类型?相同的名称?相同的部分路径?

同一所有者?相同的权限?有没有定义

相同在C ++之外的相同对象当谈到什么指针

点。 *您*需要定义相同当涉及到文件时。


V

-

请删除资金''A'时通过电子邮件回复

我没有回复最热门的回复,请不要问






鉴于原帖中的示例,我相信在/ b $ b上的realpath

函数应该在这里使用Unix。它将解析符号链接等,给出文件的

真实

路径。如果真实的

路径

相同,则两个文件路径会解析为同一个文件。


小心,
Michael。


Suppose that there is a program that takes two files as its command
line arguments. Is there a (cross platform) way to decide whether the
two files are the same? Simple string comparison is not enough as the
two files might be specified as "file.txt" and "./file.txt", or one of
them may be a symlink to the other.

[I''ve already posted this 30 min ago but it didn''t show up in Google
Groups---sorry if some people get it twice.]

解决方案

SzH wrote:

Suppose that there is a program that takes two files as its command
line arguments. Is there a (cross platform) way to decide whether the
two files are the same? Simple string comparison is not enough as the
two files might be specified as "file.txt" and "./file.txt", or one of
them may be a symlink to the other.

What does it mean for two files to be "the same"? The same contents?
The same size? The same type? The same name? The same partial path?
The same owner? The same permissions? There is no definition of
"same" in C++ beyond "same object" when speaking of to what pointers
point. *You* need to define "same" when it comes to "files".

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


I guess SzH meant paths.
I have the same question. There is something like this in .NET
Framework(Path.Equals)
but I cannot find in Win32 API or any standard libs:(


On Jan 24, 9:27 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:

SzH wrote:

Suppose that there is a program that takes two files as its command
line arguments. Is there a (cross platform) way to decide whether the
two files are the same? Simple string comparison is not enough as the
two files might be specified as "file.txt" and "./file.txt", or one of
them may be a symlink to the other.


What does it mean for two files to be "the same"? The same contents?
The same size? The same type? The same name? The same partial path?
The same owner? The same permissions? There is no definition of
"same" in C++ beyond "same object" when speaking of to what pointers
point. *You* need to define "same" when it comes to "files".

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask

Hi,

Given the example in the original post, I believe the "realpath"
function on
Unix should be of use here. It will resolve symlinks, etc, giving the
real
path to the file. Two file paths resolve to the same file if the real
paths
are the same.

Take care,
Michael.


这篇关于确定两个文件是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆