D
Wenn ich es ma so versuche:
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
char *fbprint(char *format, ...)
{
static char buf[1000];
vsnprintf(buf, sizeof(buf), format, (char *)((&format)+1));
return (char *)buf;
}
void searching(WIN32_FIND_DATA wfd, char path[],char suchen[])
{
char file[500];
FILE *fp;
char a[230];
char fil[1000] = "txt";
char laststr[5000];
char lastChar[1000];
char str[1500];
const int len = strlen(str);
strcpy(file, path);
strcat(file, "\\");
strcat(file, wfd.cFileName);
strcpy (a,path);
strcpy (str,file);
strcpy (lastChar, str+len-3);
/* Alle gefundenen Dateien überschreiben */
/* Sehr gefährlich bei */
/* dirsearch("c:\\", "*.*", REKURSIV_JA); */
/* Windows muß dann neu installiert werden*/
printf ("%s\n",lastChar);
printf ("%s\n",fil);
printf ("%s\n",file);
printf ("%s\n",str);
printf ("%s\n",wfd.cFileName);
printf ("%s\n",a);
printf ("%d\n",len);
printf ("%s\n",laststr);
system ("PAUSE");
if ((strcmp(lastChar,fil))== 0)
{
fp = fopen (file, "wt");
printf ("Es klapp\n");
if (fp)
{
fprintf(fp, "Dies ist ein Test");
fclose(fp);
}
/* wichtig: Datei-Stream wieder schließen */
}
}
void dirsearch(char *path, char *filter, int flagrekursiv)
{
HANDLE hFindFile;
WIN32_FIND_DATA wfd;
char dirfound[2000];
hFindFile = FindFirstFile(fbprint("%s\\%s", path, filter), &wfd);
if (hFindFile != INVALID_HANDLE_VALUE)
{ do
{ if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{ /* FILE_ATTRIBUTE_DIRECTORY nicht gesetzt -> kein Ordner */
searching(wfd, path,filter);
}
else /* FILE_ATTRIBUTE_DIRECTORY gesetzt -> ist Ordner */
{ if (flagrekursiv &&
strcmp(wfd.cFileName, "." ) != 0 && /* no current dir */
strcmp(wfd.cFileName, "..") != 0) /* no parent dir */
{
/* ================= */
/* rekursiver Aufruf */
/* ================= */
strcpy(dirfound, path);
strcat(dirfound, "\\");
strcat(dirfound, wfd.cFileName);
dirsearch(dirfound, filter, flagrekursiv);
dirsearch(path, filter, flagrekursiv);
}
}
}
while(FindNextFile(hFindFile, &wfd) != 0);
FindClose(hFindFile);
}
}
#define REKURSIV_NEIN 0
#define REKURSIV_JA 1
int main()
{
/* Maske "*.*" oder "*" Voraussetzung für rekursives Suchen */
dirsearch("c:\\test", "*.*", REKURSIV_JA);
getch();
return 0;
}
in meinem Ordner Test sind folgende Dateien C:\Test\juibiugfb.txt
C:\Test\Hallo.txt
C:\Test\Test1\Abc.txt
Jetzt steht aber nur In der Textdatei Abc Was.
Wie muss ich des abändern?