Code:
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
int FindFilesNow(HWND,char[],bool);
int FindFilesNow_(bool,char[]);
int end(int i)
{
return i;
}
int count_ion = 0;
int FindFilesNow_(bool isFile, char fileName[])
{
count_ion++;
return 0;
}
char title[] = "dhhg";
int main(int argc, char *argv[])
{
FindFilesNow(0,"C:\\WINNT\\",false);
return 0;
}
int FindFilesNow(HWND hwnd, char path[], bool DisplayErrors)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError;
char DirSpec[MAX_PATH + 1]; // directory specification
strcpy (DirSpec, path);
strcat (DirSpec, "\\*");
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
if(DisplayErrors == true){
char cab[MAX_PATH + 1];
wsprintf(cab,"Invalid file handle. Error is %u\n",GetLastError());
MessageBox(hwnd,cab,title,MB_OK|MB_ICONERROR); }
return end(-1);
}
else
{
int i;
for(i = 0; DirSpec[i] != '\0'; i++){
if(DirSpec[i] == '*'){
DirSpec[i] = '\\' + 0; } }
printf(DirSpec);
char source[1000];
lstrcpy(source,DirSpec);
char tempVar1[MAX_PATH];
DWORD dwAttrs = 0;
lstrcpy(tempVar1,source);
lstrcat(tempVar1,FindFileData.cFileName);
lstrcat(tempVar1,"\\");
if(rename(tempVar1,tempVar1) == 0)
{
FindFilesNow_(false,tempVar1);
FindFilesNow(hwnd,tempVar1,DisplayErrors);
}
else
{
FindFilesNow_(true,tempVar1);
}
while (FindNextFile(hFind, &FindFileData) != 0)
{
lstrcpy(tempVar1,source);
lstrcat(tempVar1,FindFileData.cFileName);
lstrcat(tempVar1,"\\");
if(rename(tempVar1,tempVar1) == 0)
{
FindFilesNow_(false,tempVar1);
FindFilesNow(hwnd,tempVar1,DisplayErrors);
}
else
{
FindFilesNow_(true,tempVar1);
}
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
if(DisplayErrors == true){
char cab[MAX_PATH + 1];
wsprintf(cab,"FindNextFile error. Error is %u\n",dwError);
MessageBox(hwnd,cab,title,MB_OK|MB_ICONERROR); }
return end(-1);
}
}
printf("\n\n\nNumber of files in C:\\WINNT\\: %d",count_ion);
return end(0);
}