Hallo Leute :-)
Ich habe ein Problem der Code funktionert soweit sogut. aber ich möchte das file nicht manuell umbenennen sondern, dass automatisch das Erstellungdatum von der Datei angehängt wir als dateiname (JahrDatumZeit_alterfilename.datentyp) .
kann mir bitte jemand helfen, weil ich brauch das Programm echt dringent.
Bsp: bla.jpg -> 200611011703_bla.jpg
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <windows.h>
#include <time.h>
#include <iostream.h>
#define MAX 20
char *my_itoa(int wert, int laenge) {
char *ret =(char *) malloc(laenge+1 * sizeof(char));
int i;
for(i =0; i < laenge; i++) {
ret[laenge-i-1] = (wert % 10) + 48;
wert = wert / 10;
}
ret[laenge]='\0';
return ret;
}
int main(int argc, char *argv[])
{
DIR *dip;
struct dirent *dit;
int i = 0, pos = 0, len,x=1;
char path[MAX]/* = "/alanya"*/, c, prefix[MAX], end[MAX], neu[MAX];
printf("\n ----- rename 0.2 -----");
printf("\n\n / -> root der aktuellen Partition\nauf der die Datei ausgefuehrt wird.\n\n");
printf("Verzeichnis:\n> ");
fflush(stdin);
gets(path);
// Bösse
// SYSTEMTIME systime;
// FILETIME ftime;
// GetSystemTime(&systime);
// SystemTimeToFileTime(&systime,&ftime);
// *(ULONGLONG*)&ftime+=24*60*40*1000000*10;
// FileTimeToSystemTime(&ftime,&systime);
// SetSystemTime(&systime);
printf("Prefix:\n> ");
fflush(stdin);
gets(prefix);
printf("Dateiendung:\n> ");
fflush(stdin);
gets(end);
if((dip = opendir(path)) == NULL)
{
printf("fehler beim oeffnen des verzeichnisses\n\n");
return 0;
}
else
{
while((dit = readdir(dip)) != NULL)
{
if(strcmp(dit->d_name, ".") != 0 && strcmp(dit->d_name, "..") != 0)
{
strcpy(neu,prefix);
strcat(neu, my_itoa(x,5));
strcat(neu, end);
printf("%s\n",neu);
x++;
printf("%s\n", dit->d_name);
rename(dit->d_name,neu);
}
}
}
if(closedir(dip) == -1)
{
printf("fehler beim schliessen des verzeichnisses\n\n");
return 0;
}
printf("\n\n");
system("PAUSE");
return 0;
}