Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3921980
  • 博文数量: 534
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4800
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(534)

文章存档

2024年(1)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类:

2007-10-16 15:28:07

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);
    }
}

阅读(2063) | 评论(0) | 转发(0) |
0

上一篇:QT学习

下一篇:可变参数宏的使用

给主人留下些什么吧!~~