How to get long directory & file name?

FindFirstFile() only returns a long file name, without directory.

As to GetFullPathName()

DWORD GetFullPathName(
LPCTSTR lpFileName,
DWORD nBufferLength,
LPTSTR lpBuffer, // address of path buffer
LPTSTR *lpFilePart // address of filename in path
);

I find if lpFileName has 8.3 format filename, lpbuffer & lpFilePart have; if lpFileName has long filename, they have long filenames too.

So how to get long directory & file name?

P.S. At first, I searched in PAQ. I found the qestion, but there were no real solutions.
henry3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WynCommented:
>>FindFirstFile() only returns a long file name, without directory.

Who tell you this?
FindFirstFile also return the 8.3 format file name in its
Here excerpt :
WIN32_FILE_DATE:
If a file has a long filename, the complete name appears in the cFileName field, and the 8.3 format truncated version of the name appears in the cAlternateFileName field. Otherwise, cAlternateFileName is empty. As an alternative, you can use the GetShortPathName function to find the 8.3 format version of a filename.

Thus ,you can use this to always obtain short name:

if(strlen(w32fd.cAlternateFileName)==0)
shortname=w32fd.cFileName;
else
shortname=w32fd.cAlternateFileName;

Regards
Wyn


 
0
henry3Author Commented:
What? Do you understand me?
I want to get LONG file name, and including LONG full path name, instead of short one.

>>FindFirstFile() only returns a long file name, without directory.
>Who tell you this?
Can you get the long directory name?
It only returns a FILE name.
e.g.
"c:\program file\1234567890.txt"
cFileName = "1234567890.txt"
I have a "c:\progra~1\123456~1.txt" string, I wanna get long one above.
0
abdijCommented:
Hi,
 Hope this is what you wanted.
The Code here first finds a text file from the programm files\\addremeove directory (you can change it to vary (FindNextFile() etc) to get the long file name. Then i use the get long directory path including the file name using the GetFullPathNa,e() function.

The key to get the long file name is       strcpy(szLongFileName,lpFindFileData->cFileName);

The GetFullPathName() automatically gives the long path+file name.

      HANDLE                        hFile                  = NULL;
      LPWIN32_FIND_DATA      lpFindFileData      = new WIN32_FIND_DATA();
      LPTSTR                        lpFileName            = new char[MAX_PATH];
      DWORD                        dwError                  = 0;
      char                        szLongFileName[MAX_SIZE];
      char                        szLongDirPath[MAX_SIZE];
      char                        szFilePart[MAX_SIZE];

      strcpy(lpFileName,"d:\\Program Files\\AddRemove\\*.txt");

      hFile  = FindFirstFile(lpFileName,lpFindFileData);
      if( (hFile = INVALID_HANDLE_VALUE) && ((dwError = GetLastError()) !=ERROR_SUCCESS))
      {
            AfxMessageBox("Error");
      }

      strcpy(szLongFileName,lpFindFileData->cFileName);

      dwError = GetFullPathName((LPCTSTR) szLongFileName,(DWORD)MAX_SIZE, (LPTSTR)szLongDirPath, (LPTSTR*)&szFilePart);

      if(lpFindFileData)
            delete lpFindFileData;
      if(lpFileName)
            delete lpFileName;

Bye for now.
Feel free to query
Abdij
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

abdijCommented:
Hi if you want the demo project feel free to ask. My mailid is abdij_b@hotmail.com.

Sorry for thr Typo mistakes in the answer. Please bear.

Abdij
0
henry3Author Commented:
I'll e-mail you to further discussion.
Thanks.
0
abdijCommented:
Hi,
 You are welcome.
Bye
Abdij
abdij_b@hotmail.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.