Read a file from any drive

Microsoft Visual c++ enterprise edition...
January 7, 2010 at 11:49:49
Specs: Microsoft Windows XP Professional, 2 GHz / 1021 MB
Now that I'm nearly finished with coding a movie plugin, how do I shorten the text of a file's full directory so it can open from any drive?

Thank You.


See More: Read a file from any drive

Report •


#1
January 7, 2010 at 12:09:40
Not sure if it's what you're asking, but you might try GetShortPathName

#include <windows.h>
#include <stdio.h>

#define MYPATH "C:\\Documents and Settings\\Administrator\\My Documents"

int main(void) {

   char spath[MAX_PATH] = { 0 };
   DWORD nbytes = GetShortPathName(TEXT(MYPATH), spath, sizeof spath);   

   puts(spath);

   return (0);
} 

HTH


Report •

#2
January 7, 2010 at 12:35:18
I was hoping for a code that get a file's full path and enters it as 'path + file.ext', but that is good. Thank you.

Thank You.


Report •

#3
January 7, 2010 at 13:52:46
As long as the file exists, it *should* give you the short file name as well. You can get the full name again with GetLongPathName

For example, with an empty new text document created in my documents.

#include <windows.h>
#include <stdio.h>

#define MYPATH "C:\\Documents and Settings\\Administrator\\My Documents\\New Text Document.txt"

int main(void) {

   char spath[MAX_PATH] = { 0 };
   char lpath[MAX_PATH] = { 0 };

   DWORD nbytes = GetShortPathName(MYPATH, spath, sizeof spath);  
   DWORD num = GetLongPathName(spath, lpath, sizeof lpath);

   printf("%s\n%s", spath, lpath);   

   return (0);
} 

HTH


Report •
Related Solutions


Ask Question