0

I am coding in Borland C++Builder 6. In several of my applications I am using the following function to locate files on our network:

String sRootDir="N:\\";
String sClmNbr="748000";
TSearchRec fnd1;

if (FindFirst(sRootDir+sClmNbr+"*.PDF",faAnyFile,fnd1)==0)
{
    lbClmCpy->Lines->Add(fnd1.Name);    
    while (FindNext(fnd1)==0)
        {lbClmCpy->Lines->Add(fnd1.Name);}
    FindClose(fnd1);    
}

This is a watered-down version of the function, but you can see what I am trying to accomplish. I attempted to search for any file on N: with a mask of 748000*.*.

However, the function returns files that do not match the mask. After doing some digging, I discovered that it has to do with the 8.3 short names of the files. For whatever reason, the short names of the files are completely wrong. For example, 748123_20161110.pdf should look something like 748123~1.pdf, instead it shows 748AE4~1.PDF. I know a work-around (by checking the 'Name' value on the file found, which would give me the full name, and then check the full name). However, this is crazy.

I have a few questions here:

  1. Why would the short names be formatted incorrectly?

  2. Is there a way to tell FindFirst()/FindNext() to search for only long file names? If not, does anyone have an alternate function that could be used?

  3. There is a DOS command to disable short names completely. Are there any dangers when doing this? Also, if I disable this option on our network drive, will that suffice? All of the file operations take place from end-user pc's (do I have to disable short names on the individual PC's?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    What are all these functions and classes? they don't look like the STL ones. Are you using some library? (if yes, which one) – UnholySheep Nov 22 '16 at 16:44
  • 2
    _"the short names of the files are completely wrong"_: Because the file system had exhausted `748123~1` to `748123~9` ... after that it has to start making up names. If I remember correctly disabling short-names only disables the generation of short-names for new files. PS Borland C++ Builder 6 is dated about 2001 - suggest updating your compiler if you can. – Richard Critten Nov 22 '16 at 16:47
  • 2
    You could use the WinAPI functions `FindFirstFile`, `FindNextFile` and `FindClose` (https://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx) – Simon Kraemer Nov 22 '16 at 16:51
  • @SimonKraemer: Borland's `FindFirst()`/`FindNext()` are just wrappers for `FindFirstFile()`/`FindNextFile()`. – Remy Lebeau Nov 22 '16 at 17:19
  • See [Why does FindFirstFile find short names?](https://blogs.msdn.microsoft.com/oldnewthing/20050720-16/?p=34883) – Remy Lebeau Nov 22 '16 at 17:24
  • Thank you everyone for you responses. – Kyle Olson Nov 22 '16 at 17:38

0 Answers0