Using Dir Problem

kirkm

Registered User.
Local time
Today, 23:57
Joined
Oct 30, 2008
Messages
1,257
File = Dir(FileSpec)

Returns the correct file but the name is not the same case as the filename in Explorer.
Can I fix this anyhow ?
 
What case do you want? Give example. Why does it matter?
 
Yes it matters. The case wanted is the case that it *is*.
Do you want more ?
 
Unless you are using a POSIX environment, Windows file names are not case sensitive.

See, for example,

https://superuser.com/questions/165975/are-all-versions-of-windows-case-insensitive

You can try to enable case sensitivity if you really wanted to do so.

https://technet.microsoft.com/en-us/library/cc725747(v=ws.11).aspx

Here is another explanation for Win7.

https://superuser.com/questions/266...case-sensitive-with-respect-to-the-filesystem

As you can see if you read through these items, Windows is not case sensitive without some work. I have to ask: What is it that you see in explorer that you don't see (but expected to see) using the File=Dir(spec) syntax?
 
Thanks for those links, and yes I've just been reading on Google much the same thing.

It's to ensure things like "MacDonald" are not "Macdonald". But if I cannot tell if the casing is correct, maybe I can rename it with the casing known.

After some tests it seems not, unless a change occurs in the filename. So it would require renaming twice. Do you agree (or perhaps have another method)? It just seems wrong that the name (as it appears in Explorer) can't be retrieved.
 
You could try enumerating the Files Collection of the directory using the FileSystemObject.

Basically the VB Script shown on this page.
 
Many thanks Galaxiom, that looks like the perfect solution. :)
A quick tryout shows it working just as hoped.
 
That's one of the (simultaneously) fun, maddening thing about working in modern operating systems. You have more than one way to get to things and each way has its own unique little wrinkles.
 
I would have tried your link that used Administrative Tools, and Services for Network File System, except that the drive is mapped on a LAN and i expected that to cause more trouble than I could solve!
The file system method is perfect, but I wonder - should i call it once - then use the result, or call it individually for each file? Or does it matter ? Speed isn't important.

I would send in the filename to the function and return true or false (adding that logic to the function); or get the output, split it on BR, Filter the array, and use Strcomp on the result. Does either way stand out as best ?
 
Your last sentence is actually the first time I've seen in your post that you have an ulterior motive. What is it that you were trying to do - in English - that would involve the ability to return a T/F result?
 
Ulterior motive? Not sure I follow... T/F indicates whether the casing of the filename is the same as in the Access table.

But a footnote... my original claim that File = Dir(FileSpec) didn't return whatever casing was in use - now appears wrong. Or at least wasn't working then, but is now. So it can't be relied on and I've gone to make it what I want regardless as the FileObject method was just a bit too slow.
 
casing of the filename is the same as in the Access table.

Question still stands, if filenames aren't case sensitive in Windows, why does your application rely on it? You can't have two files in the same directory with different cases.
 
Not sure how to answer. The goal was simply to ensure both are the same. And a correction in Access would reflect in the filename. I first wanted to confirm they were or weren't (the same) but couldn't reliably detect that. It may well have been unnecessary as in the end all were made the same as Access whether they needed it or not. I never wanted two files in the same directory with different cases.
 
I understand your point.
I've tried and haven't been able to replicate this problem. Consistency is always good, but I don't see how it is critical in this case.
 
Actually I think if you were linking the document via a web page the case would matter. Web addresses are case sensitive, even if the target isn't.

I would add I haven't tested this theory.

Sent from my Nexus 7 using Tapatalk
 
Minty, IN THEORY a web page reference to a file is case-sensitive if and only if the underlying file system is case-sensitive because (again IN THEORY) the interfaces used between the web page and file system should be native to the file system. Thus the normal rule is that the web page should honor the file system conventions.

That said, there ARE times when you run afoul of case sensitivity in Windows-based web apps. The one that always got me miffed was when we had a web page that used FTP to implement its file transfer rather than some other method. I was always fighting that case because I was

-talking to Windows that was
-talking to a web page that was
-talking via FTP protocol across a network to an FTP server that was
-talking to a file system interface that was
-talking to a disk with unknown format depending on what the O/S had done when it built that disk volume.

The FTPs on either side of the network connection were negotiating file names and formats each according to local rules, made more complex by the presence of the web interface. The wonder was that I didn't go postal... (well, for me it would have been "naval") in the midst of all of these shaky negotiations.
 

Users who are viewing this thread

Back
Top Bottom