I have a problem. my program works but i can't rename mi files to creation time
program must rename files in a folder.
Example:
old file names
bla1.jpg ->2007(year)1010(Date)1100(time)_bla1.jpg
bla2.jpg ->200710101100_bla2.jpg
Code:
#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;
}
thx for help!