美文网首页
Windows编程之文件操作

Windows编程之文件操作

作者: Pino_HD | 来源:发表于2018-09-27 17:15 被阅读0次



欢迎关注我的新博客 https://pino-hd.github.io,最新的博文都会发布在上面哦~

Windows编程之文件操作

该程序主要功能就是创建一个文件,然后在文件的后面追加数据,之后将文件复制到上层目录,然后将其重命名,最后再删除。
所应用到的windows函数有CreateFile, WriteFile, CopyFile, MoveFile, DeleteFile, SetFilePointer

代码


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


int main(int argc, char* argv[]) {
    HANDLE hFile = CreateFile(argv[1], GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE) {
        printf("Create failed\n");
        return 0;
    }
    if (SetFilePointer(hFile, 0, NULL, FILE_END) == -1) {
        printf("SetFilePointer error\n");
        return 0;
    }
    char buff[] = "配置信息";
    DWORD dwWrite;
    if (!WriteFile(hFile, &buff, strlen(buff), &dwWrite, NULL)) {
        printf("Writer error\n");
        return 0;
    }
    printf("往%s写入数据成功\n", argv[1]);
    char newCopyPath[] = "../2.txt";
    char newMovePath[] = "../3.txt";
    if (!CopyFile(argv[1], newCopyPath, FALSE)) {
        printf("CopyFile error\n");
        return 0;
    }
    if (!MoveFile(newCopyPath, newMovePath)) {
        printf("MoveFile error\n");
        return 0;
    }
    if (!DeleteFile(newMovePath)) {
        printf("DeleteFile error\n");
        return 0;
    }
    CloseHandle(hFile);
    return 0;
}

相关文章

  • Windows编程之文件操作

    欢迎关注我的新博客 https://pino-hd.github.io,最新的博文都会发布在上面哦~ Window...

  • eclipse设置所有文档显示与保存皆为utf-8

    Windows 7平台默认为GBK,简体中文操作系统Windows XP、Windows 2000简体中文的缺省编...

  • 文件描述符

    文件描述符是操作系统暴露给应用程序操作文件的句柄,Linux 称为 fd,windows 称 handle。 文件...

  • Windows文件操作命令

    1.显示当前目录下的文件和目录 2.创建目录sub1 3.进入到目录sub1中 4.创建一个文件file1.txt...

  • 原版纯净 windows 10

    文件名 windows 10 64位操作系统 en_windows_10_multi-edition_vl_ver...

  • 原版纯净 windows 7

    文件名 windows 7 专业版 64位操作系统 cn_windows_7_professional_with_...

  • cat命令

    ``` -A 参数 #查看文件所有内容,包括隐藏字符 ``` linux 中文件回车符识别为$ windows中编...

  • 原版纯净 windows 8.1

    文件名 windows8.1 64位操作系统 cn_windows_8.1_with_update_x64_dvd...

  • Ubuntu终端中的文件操作

    文件操作 在Windows等平台中,经常会用到的文件操作有复制、剪切、删除等,在桌面环境中进行这些操作,通常需要使...

  • JAVA并发编程-基本概念

    基本概念 程序、进程、线程之间的概念 程序是静态的概念windows下通常指exe 文件 linux 下 ja...

网友评论

      本文标题:Windows编程之文件操作

      本文链接:https://www.haomeiwen.com/subject/svtyoftx.html