473,561 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deciding whether two files are the same

SzH
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.]
Jan 24 '08 #1
28 2477
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
Jan 24 '08 #2
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:(
Jan 24 '08 #3
On Jan 24, 9:27 am, "Victor Bazarov" <v.Abaza...@com Acast.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.
Jan 24 '08 #4
and what would that be in Windows? anybody knows?:)

Jan 24 '08 #5
Inquirer wrote:
and what would that be in Windows? anybody knows?:)
Somebody in a Windows programming newsgroup might... Here
we don't discuss platform-specific functionality, sorry.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 24 '08 #6
On Jan 24, 12:01 pm, SzH <szhor...@gmail .comwrote:
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.
Out of curiosity, I looked in Boost.Filesyste m.

You may be interested in the "equivalent ()" function:
http://www.boost.org/libs/filesystem...cate-functions
Jan 24 '08 #7
On Jan 24, 10:27 am, "Victor Bazarov" <v.Abaza...@com Acast.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".
Based on his example it looks like he wants to know if two given
references refer to the same file.
Jan 24 '08 #8
On Jan 24, 10:58 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Inquirer wrote:
and what would that be in Windows? anybody knows?:)

Somebody in a Windows programming newsgroup might... Here
we don't discuss platform-specific functionality, sorry.
However, the original poster asked about cross-platform methods.
Do any exist?
Jan 24 '08 #9
mike3 wrote:
On Jan 24, 10:58 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>Inquirer wrote:
>>and what would that be in Windows? anybody knows?:)

Somebody in a Windows programming newsgroup might... Here
we don't discuss platform-specific functionality, sorry.

However, the original poster asked about cross-platform methods.
Do any exist?
Cross which platforms? Not all platforms have files.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2019
by: KN | last post by:
I know both are pretty much the same and it comes down to personal choice. But I have to make the choice for the team. Things so far that I am considering 1. XML documentation in C# -- thats good.. not there in VB.net?? 2. Some language features of VB.Net like Redim(makes it easier for developers), but not good enough reason. 3. C# is...
0
253
by: Saurabh | last post by:
I require urgently guidelines to aid in deciding whether to go for a FAT Client Application or a Client-Server Application model. Like Pros and Cons related to the Performance issue in both the above models seeking your help ....... thanx in advance Saurabh
6
1832
by: Charlie Garrett-Jones | last post by:
i have a server side generated web application that provides parameter forms and always opens the associated reports in a new browser window. the code that controls the opening of the new browser window is simply html target='_blank'. but now there is some business rules that may be checked server side only. so if the data provided fails, i...
2
1284
by: Fred Mertz | last post by:
I'd like to know the rationalle some of you use for deciding which members of System.IO you use to do your file I/O. It appears that there are many ways to accomplish any task (reading from a text file, for example). Did the framework designers have any particular *intention* for how we're supposed to do these basic tasks? Just looking for...
0
7647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7570
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7618
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5472
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.