473,414 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Determining if two paths are the same

Hi there,

Given two file names in relative or absolute format, I need to determine if
they point to the same file. While I can simply pass each to
"Path.GetFullPath()" and compare the results, what is the rule regarding
case. That is, how do you determine whether the local file system is
case-sensitive or not. I don't want to assume that Windows is the target OS
even though realistically it will be. Thanks.
Apr 30 '07 #1
10 4891
Windows File System is non-case-sensitive. Unix and some others are
case-sensitive.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Mark Chambers" <no_spam@_nospam.comwrote in message
news:Om**************@TK2MSFTNGP04.phx.gbl...
Hi there,

Given two file names in relative or absolute format, I need to determine
if they point to the same file. While I can simply pass each to
"Path.GetFullPath()" and compare the results, what is the rule regarding
case. That is, how do you determine whether the local file system is
case-sensitive or not. I don't want to assume that Windows is the target
OS even though realistically it will be. Thanks.

Apr 30 '07 #2
Windows File System is non-case-sensitive. Unix and some others are
case-sensitive.
Thanks. I'm trying to find the appropriate .NET function that tells me that
however.
Apr 30 '07 #3
On Mon, 30 Apr 2007 10:21:06 -0700, Mark Chambers <no_spam@_nospam.com>
wrote:
>Windows File System is non-case-sensitive. Unix and some others are
case-sensitive.

Thanks. I'm trying to find the appropriate .NET function that tells me
that however.
I don't know of any (though that doesn't mean it doesn't exist). If one
exists, it seems to me that it would have to be in some component that
actually accesses the file. Like something that gets all of the file
properties, or opens the file, or something like that.

That said, you should probably keep in mind that because of various ways
to alias a file, even if the paths are different based on a simple string
comparison, whether you correctly deal with case-sensitivity or not, you
could still have false negatives. You goal sounds like something you
should only be trying if it's not 100% important that you always get the
right answer.

Pete
May 1 '07 #4
To be honest I dont think there is one.

Not one that I have ever seen.

Since the Microsoft DotNet framework is really for use on Windows machines I
think that it is assumed that they are not case sensitive.

"Mark Chambers" <no_spam@_nospam.comwrote in message
news:OP**************@TK2MSFTNGP02.phx.gbl...
>Windows File System is non-case-sensitive. Unix and some others are
case-sensitive.

Thanks. I'm trying to find the appropriate .NET function that tells me
that however.

May 1 '07 #5
I don't know of any (though that doesn't mean it doesn't exist). If one
exists, it seems to me that it would have to be in some component that
actually accesses the file. Like something that gets all of the file
properties, or opens the file, or something like that.
I think otherwise actually :) It seems more likely that such a function
would probably be part of some class that provides system-wide info about
the environment or OS itself (or the file system)
That said, you should probably keep in mind that because of various ways
to alias a file, even if the paths are different based on a simple string
comparison, whether you correctly deal with case-sensitivity or not, you
could still have false negatives.
Yes you're right. It's possible when comparing a UNC name and an ordinary
file name for instance. Sometimes quirky rules also exist that make the task
harder, such as cases where successive backslashes are accepted by some
functions (the "Path.DirectorySeparatorChar" in .NET actually). I've seen
this using the WinAPI. The actual rules for forming names can get quite
elaborate in fact so it is possible that two strings might not compare equal
yet point to the same file. Unfortunately, there seems to be no
comprehensive function which deals with this so I have no choice but to rely
on "Path.GetFullPath()" (without turning to more complicated and/or esoteric
techniques). In practice however comparing the results of
"Path.GetFullPath()" should effectively handle 99% of the cases in theory.
(which I can live with).
You goal sounds like something you should only be trying if it's not 100%
important that you always get the right answer.
It isn't 100% important fortunately. However, case-sensitivity is something
I'd like to factor into the equation.

Thanks for your feedback.
May 1 '07 #6
To be honest I dont think there is one.
>
Not one that I have ever seen.

Since the Microsoft DotNet framework is really for use on Windows machines
I think that it is assumed that they are not case sensitive.
Thanks for the feedback. In practice you're right, .NET is really for
Windows at this point in time but I don't think it should be treated that
way. It's a generic platform so no assumptions should be made about the
underlying OS IMO, especially if your program or its descendants might still
be around in 10 years.
May 1 '07 #7
On Mon, 30 Apr 2007 18:48:42 -0700, Mark Chambers <no_spam@_nospam.com>
wrote:
>I don't know of any (though that doesn't mean it doesn't exist). If one
exists, it seems to me that it would have to be in some component that
actually accesses the file. Like something that gets all of the file
properties, or opens the file, or something like that.

I think otherwise actually :) It seems more likely that such a function
would probably be part of some class that provides system-wide info about
the environment or OS itself (or the file system)
Well, that's just it. The system you're running on is not necessarily the
system the file lives on, nor is it necessarily the case that the system
you're running on supports only one kind of file system. You can't tell
just from looking at a string what kind of file system the file resides
on. You'll have to actually access the file directly, or at least its
storage location, in order to know for sure what the file naming rules for
the file are.

Pete
May 1 '07 #8
Well, that's just it. The system you're running on is not necessarily the
system the file lives on, nor is it necessarily the case that the system
you're running on supports only one kind of file system. You can't tell
just from looking at a string what kind of file system the file resides
on. You'll have to actually access the file directly, or at least its
storage location, in order to know for sure what the file naming rules for
the file are.
What you're saying has merit but they're not practical issues to begin with.
Clearly you can't concern yourself with files that don't reside on the same
system for instance. Even on the same machine however, you can be dealing
with a UNC name or other mapping system so that "C:\Whatever\MyFile" and
"\\MyMachine\Test\MyFile" are really the same physical file. You may or may
not be able to determine this however depending on the system or simply
because your access rights prevent it (i.e., you may not have the rights to
call the appropriate function to unravel things). Accessing the file itself
in some way may not be possible either if you lack sufficient rights. As for
systems supporting multiple file systems, this is usually less of an issue
because you'll usually be dealing with one system only and/or you can
typically map from one to the other (if you have the rights). Even under
Windows, using NTFS or FAT with short an/or long names, you can determine if
two files are the same with minimal effort. Ultimately however, the final
arbiter of what you can or can't determine is the system itself. No function
in a generic platform like .NET can ever hope to circumvent this (or deal
with all possible situations). You're therefore forced to be both realistic
and practical about things. Relying on "Path.GetFullPath()" or some other
function (since the latter does require rights if the file exists) and then
comparing the names, is really the only "generic" method at your disposal.
It's not perfect but will realistically handle most cases for whatever file
naming convention is in effect on the local system. Case-sensitivity should
therefore be factored into the equation IMO.
May 1 '07 #9

"Mark Chambers" <no_spam@_nospam.comwrote in message
news:er**************@TK2MSFTNGP05.phx.gbl...
>To be honest I dont think there is one.

Not one that I have ever seen.

Since the Microsoft DotNet framework is really for use on Windows
machines I think that it is assumed that they are not case sensitive.

Thanks for the feedback. In practice you're right, .NET is really for
Windows at this point in time but I don't think it should be treated that
way. It's a generic platform so no assumptions should be made about the
underlying OS IMO, especially if your program or its descendants might
still be around in 10 years.
While I agree I would like to point out that, while the concept of the
framework itself is to be cross platform, the released version at this point
is really only for Windows and they (MS) Have not really added anything yet
that indicates it is truly cross platform. There are bits that allow cross
platform communications (serialization and such) but the framework itself is
Windows.

Looking for cross platform perhaps a look at the Mono project source code
would shed some light.

Perhaps this is an opening for you to write a cross platform library that
returns this information :)
May 1 '07 #10
I would argue with you and say that the windows file system, NTFS as it is,
is in fact case sensitive. It's win32 that is case insensitive.

Regards
Kjetil Kristoffer Solberg
"Kevin Spencer" <un**********@nothinks.comwrote in message
news:eN**************@TK2MSFTNGP03.phx.gbl...
Windows File System is non-case-sensitive. Unix and some others are
case-sensitive.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Mark Chambers" <no_spam@_nospam.comwrote in message
news:Om**************@TK2MSFTNGP04.phx.gbl...
>Hi there,

Given two file names in relative or absolute format, I need to determine
if they point to the same file. While I can simply pass each to
"Path.GetFullPath()" and compare the results, what is the rule regarding
case. That is, how do you determine whether the local file system is
case-sensitive or not. I don't want to assume that Windows is the target
OS even though realistically it will be. Thanks.

May 4 '07 #11

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

Similar topics

4
by: Chad Richardson | last post by:
As I'm writing this I think I am answering my own question, but I'd like to get any other ideas on the subject as well. I have a standard Header.asp that I want to include in every other page in...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
1
by: Phil Galey | last post by:
In VB.NET, when you use shell or have a process object point to and run a separate application that is installed on the machine, is there a way of determining the path to the executable? I've been...
3
by: JeffDotNet | last post by:
I wrote a small data processing application that writes a summary of several hundred files. I use drag and drop on a panel (Panel1) to grab the absolute path to each of these files. Then I begin...
5
by: costantinos | last post by:
Hello. I have implemented the Dijkstra shortest path algorithm, it works fine but I have one question on how I can improve something. I want to find all the possible shortest paths from a node...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
8
by: =?Utf-8?B?R2VvcmdlQXRraW5z?= | last post by:
Greetings! I wrote a small Exe that simply runs Shell to load PowerPoint and launch a particular file, depending on the day of the week. However, it was set up for office 2003 (I naively hardcoded...
6
by: Ole Nielsby | last post by:
The standard doesn't define this but what conventions do projects use? As I understand it, #include <somelibrary.h> is used for including system headers and those of frameworks such as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.