开发者

delete,copy,rename files and directories in WINAPI ..?

开发者 https://www.devze.com 2023-01-01 16:44 出处:网络
hi I made a code that search in a givin path for a certain file name or folder and print the value BUT now how can i modify it to instead of printing its name perform on of the operations ( delete,cop

hi I made a code that search in a givin path for a certain file name or folder and print the value BUT now how can i modify it to instead of printing its name perform on of the operations ( delete,copy,rename ) I searched on google and found nothin.

#include "stdafx.h"
#include <windows.h>


int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR *fn;
    fn=L"d:\\*";
    HANDLE f;

    WIN32_FIND_DATA data;

    f=FindFirstFile(fn,&data);
    if(f==INVALID_HANDLE_VALUE){
        printf("not found\n");
        return 0;
    }
    else{


        _tprintf(L"found this file: %s\n",data.c开发者_如何转开发FileName);
        }
        while(FindNextFile(f,&data)){

        {
        _tprintf(L"found this file: %s\n",data.cFileName);
        }

        }
    }

    FindClose(f);
    return 0;
}


See file management functions: http://msdn.microsoft.com/en-us/library/aa364232%28v=VS.85%29.aspx

DeleteFile, CopyFile, MoveFile (can be used for renaming).

I think it is dangerous to make these operations inside of FindFirstFile - FindNextFile loop. This may affect correct files enumeration. I would make these changes only after the loop.


To copy a file use CopyFile, to rename or move a file use MoveFile and to delete a file use DeleteFile. More: http://msdn.microsoft.com/en-us/library/aa364232(VS.85).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消