[racket] reliable path comparison?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Oct 21 12:53:52 EDT 2010

Normal-case-path?

On Thursday, October 21, 2010, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> On Thu, Oct 21, 2010 at 11:23 AM, scouic <scouic at gmail.com> wrote:
>> Hi,
>> i think that the problem is the \ character, because this works :
>> #lang racket
>> (equal? (regexp-replace* "\\\\" (path->string (build-path "C:\\")) "/")
>>         (regexp-replace* "\\\\" (path->string (build-path "C:\\")) "/"))
>>
>> and returns true
>
>
> Unfortunately, I'm occasionally getting paths where the entire path is
> lowercased, and at other times, I'm getting it in mixed case: case
> sensitivity is the issue I'm hitting.
>
> The unsatisfactory solution I've got so far is:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;; same-path?: path path -> boolean
> ;; Produces true if both paths are pointing to the same file.
> (define (same-path? p1 p2)
>   (cond
>     [(eq? (system-path-convention-type) 'windows)
>      (string=? (string-downcase (path->string (normalize-path p1)))
>                (string-downcase (path->string (normalize-path p2))))]
>     [else
>      (string=? (path->string (normalize-path p1))
>                (path->string (normalize-path p2)))]))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.