tags:

views:

79

answers:

2

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.cFileName);
        }
        while(FindNextFile(f,&data)){

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

        }
    }

    FindClose(f);
    return 0;
}
+2  A: 

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

VuuRWerK
+3  A: 

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.

Alex Farber