M
M&M
I understand that windows filesystems are case insensitive though case
preserving. My dilema is that files on my windows server are synced
to a linux web server where case sensitivity does matter.
Is there a way to simulate "-f test.txt" in a case sensitive manner or
perhaps retrieve a file's actual name? I was surprised to learn that
neither glob("test.txt") nor <test.txt> do the job without using
wildcards. I've searched the cpan, faqs, google groups and the
cookbook to no avail.
I've come up with the following but it's very inefficient for
real_filename() to read the directory each time (especially if it is
very large). Sure, I could cache the dir contents in a list or hash,
but then I have the complexity of maintaining it as changes occur. It
works, but how could it be improved? (It doesn't even address
directories...) Certainly others have dealt with this before. Any
suggestions?
Thanks,
Marco Moreno
#!/usr/bin/perl -w
chdir "c:/temp";
my $file = "test.txt";
if (-f $file and not really_exists($file)) {
my $realname = real_filename($file);
warn "Renaming $realname to $file.\n";
rename $realname, $file or die "Can't rename $realname: \n";
}
sub really_exists {
my $filename = shift;
return $filename eq real_filename($filename) ? 1 : 0;
}
sub real_filename {
my $filename = shift;
opendir DIR, "." or die "Can't readdir: $!";
(my $realname) = grep { $filename =~ /^${_}$/i } readdir DIR;
closedir DIR;
return $realname;
}
preserving. My dilema is that files on my windows server are synced
to a linux web server where case sensitivity does matter.
Is there a way to simulate "-f test.txt" in a case sensitive manner or
perhaps retrieve a file's actual name? I was surprised to learn that
neither glob("test.txt") nor <test.txt> do the job without using
wildcards. I've searched the cpan, faqs, google groups and the
cookbook to no avail.
I've come up with the following but it's very inefficient for
real_filename() to read the directory each time (especially if it is
very large). Sure, I could cache the dir contents in a list or hash,
but then I have the complexity of maintaining it as changes occur. It
works, but how could it be improved? (It doesn't even address
directories...) Certainly others have dealt with this before. Any
suggestions?
Thanks,
Marco Moreno
#!/usr/bin/perl -w
chdir "c:/temp";
my $file = "test.txt";
if (-f $file and not really_exists($file)) {
my $realname = real_filename($file);
warn "Renaming $realname to $file.\n";
rename $realname, $file or die "Can't rename $realname: \n";
}
sub really_exists {
my $filename = shift;
return $filename eq real_filename($filename) ? 1 : 0;
}
sub real_filename {
my $filename = shift;
opendir DIR, "." or die "Can't readdir: $!";
(my $realname) = grep { $filename =~ /^${_}$/i } readdir DIR;
closedir DIR;
return $realname;
}