OS :
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.
===================
#include <Windows.h>
#include <stdio.h>
#define BUFSIZE 4096
int main(int argc, char *argv[])
{
DWORD retval = 0;
BOOL success;
char buffer[BUFSIZE] = "";
char *lpPart[BUFSIZE] = {NULL};
/*
Retrieve a full path name for a file. The file does not need to exist.
提取文件的全名
如: 当前目录下的aa.c文件(当前目录为c:\win32),那么就可以得到为"c:\win32\aa.c"
*/
retval = GetFullPathName("t1.c", BUFSIZE, buffer, NULL);
if (retval == 0)
{
// Handle an error condition.
printf ("GetFullPathName failed with error %d.\n", GetLastError());
return (1);
}
else
printf("The full path name for the file test.txt is: %s\n", buffer);
// Create a long directory name for use with the next two examples.
success = CreateDirectory("c:\\longdirectoryname", NULL); // No security attributes.
if (!success)
{
// Handle an error condition.
printf ("CreateDirectory failed with error %d.\n", GetLastError());
return (1);
}
// Retrieve the short path name.
retval = GetShortPathName("c:\\longdirectoryname", buffer, BUFSIZE);
if (retval == 0)
{
// Handle an error condition.
printf ("GetShortPathName failed with error %d.\n", GetLastError());
return (1);
}
else
printf("The short path name for the directory "
"c:\\longdirectoryname is: %s\n", buffer);
// Retrieve the long path name.
retval = GetLongPathName("c:\\LONGDI~1", buffer, BUFSIZE);
if (retval == 0)
{
// Handle an error condition.
printf ("GetLongPathName failed with error %d.\n", GetLastError());
return (1);
}
else
printf("The long path name for the directory "
"c:\\longdirectoryname is: %s\n", buffer);
// Clean up the directory.
success = RemoveDirectory("c:\\longdirectoryname");
if (!success)
{
// Handle an error condition.
printf ("RemoveDirectory failed with error %d.\n", GetLastError());
return (1);
}
}
|
阅读(2098) | 评论(0) | 转发(0) |