| | |
| Stránka: 1 z 1
| [ Príspevkov: 6 ] | |
Autor | Správa |
---|
Registrovaný: 19.06.12 Prihlásený: 11.12.17 Príspevky: 132 Témy: 20 | Napísal expoox: 09.10.2013 19:34 | |
|
Zdravim, neviete mi niekto poradit ako zistim ( idealne v pascale ale aj C/C++ riesenie pomoze ) poslednu zmenu isteho suboru ? dakujem
_________________ Lenovo IdeaPad G580 *Intel Core i3-2310M 2.10GHz * 4GB RAM * Nvidia GeForce 610M 1GB * 500GB HDD SATA * Windows 10 64-bit || Ubuntu 14.04 |
|
Registrovaný: 07.04.12 Prihlásený: 02.06.21 Príspevky: 907 Témy: 54 | Napísal ado130: 09.10.2013 19:47 | |
|
V C napr.: Kód: #include <time.h> #include <stdio.h> #include <conio.h> #include <sys/types.h> #include <sys/stat.h>
int main() { char file[] = "c:\\Hello.txt"; char t[ 100 ] = ""; struct stat b; if (!stat(file, &b)) { strftime(t, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime)); printf("\nLast modified date and time = %s\n", t); } else { printf("Cannot display the time.\n"); } getch(); return 0; }
_________________ Notebook: Dell Inspiron 15-7537= i5-4200U|nVidia GT 750M 2GB|RAM 6GB|250GB Samsung 850 EVO|W8.1|Cooler Master NotePal U3 Pc: Asus Rog Strix B360-G | i7-8700 | MSI 1080 Gaming X | Crucial Ballistix 16GB 2666MHz Dual Ranked | Samsung 970 Evo | Crucial MX500 | WD Red | Fera 3 | Arctic F12 Silent | Seasonic Focus Plus 650W Gold | Fractal Design Mini C TG Disk: Western Digital Elements 1TB USB 2.0; Seagate Expansion 2TB USB 3.0 Príslušenstvo: A4tech Bloody V3 V-Track Core 3 + A4tech Bloody B-070; A4tech Bloody B120; A4tech Bloody G501; ATH-M40x; MSI Clutch M40 Monitor: Dell U2515H Mobil: Xiaomi Redmi Note 3 Special Edition |
|
Registrovaný: 19.06.12 Prihlásený: 11.12.17 Príspevky: 132 Témy: 20 | Napísal autor témy expoox: 09.10.2013 19:54 | |
|
Dakujem za kod, krasne funguje no zda sa ze v Ccku mi to az tak nejde ako som si myslel tak by som potreboval este malu pomoc, ako sa da prehladavat jedna zlozka takym sposobom ze kazdemu jednemu suboru zisti datum poslednej zmeny a porovna ho s aktualnym datumom? dakujem pekne
_________________ Lenovo IdeaPad G580 *Intel Core i3-2310M 2.10GHz * 4GB RAM * Nvidia GeForce 610M 1GB * 500GB HDD SATA * Windows 10 64-bit || Ubuntu 14.04 |
|
Registrovaný: 07.04.12 Prihlásený: 02.06.21 Príspevky: 907 Témy: 54 | Napísal ado130: 09.10.2013 21:39 | |
|
Kód: #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <string.h> #include <errno.h> #include <time.h> #include <conio.h> #include <sys/stat.h>
int main () { DIR * d; char * dir_name = "C:\\Documents and Settings"; //cesta k zložke char t[ 100 ] = ""; struct stat b; time_t rawtime; struct tm *timeinfo; char buffer[80]; time( &rawtime ); timeinfo = localtime( &rawtime );
/* Open the current directory. */
d = opendir (dir_name);
if (! d) { fprintf (stderr, "Cannot open directory '%s': %s\n", dir_name, strerror (errno)); exit (EXIT_FAILURE); } while (1) { struct dirent * entry; entry = readdir (d); if (! entry) { break; } printf("_________________________________________________ \n"); printf("%s\n", entry->d_name); //char file[] = "entry->d_name"; if (!stat(entry->d_name, &b)) { strftime(t, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime)); printf("\nLast modified date and time = %s\n", t); } else { printf("Cannot display the time.\n"); } strftime ( buffer, 80, "Time: %d/%m/%Y %H:%M:%S", timeinfo ); printf( "%s\n", buffer ); printf("------------------------------------------------- \n"); printf("\n"); printf("\n"); } /* Close the directory. */ if (closedir (d)) { fprintf (stderr, "Could not close '%s': %s\n", dir_name, strerror (errno)); exit (EXIT_FAILURE); } getch(); return 0; }
_________________ Notebook: Dell Inspiron 15-7537= i5-4200U|nVidia GT 750M 2GB|RAM 6GB|250GB Samsung 850 EVO|W8.1|Cooler Master NotePal U3 Pc: Asus Rog Strix B360-G | i7-8700 | MSI 1080 Gaming X | Crucial Ballistix 16GB 2666MHz Dual Ranked | Samsung 970 Evo | Crucial MX500 | WD Red | Fera 3 | Arctic F12 Silent | Seasonic Focus Plus 650W Gold | Fractal Design Mini C TG Disk: Western Digital Elements 1TB USB 2.0; Seagate Expansion 2TB USB 3.0 Príslušenstvo: A4tech Bloody V3 V-Track Core 3 + A4tech Bloody B-070; A4tech Bloody B120; A4tech Bloody G501; ATH-M40x; MSI Clutch M40 Monitor: Dell U2515H Mobil: Xiaomi Redmi Note 3 Special Edition |
|
Registrovaný: 19.06.12 Prihlásený: 11.12.17 Príspevky: 132 Témy: 20 | Napísal autor témy expoox: 09.10.2013 22:09 | |
|
Ďakujem, a naozaj posledny dotaz, neda sa ten datum poslednej zmeny nahradit datumom posledneho otvorenia ?
EDIT:// vlastne ani netreba menit na datum posledneho otvorenia, len ten druhy kod potom nefunguje velmi lebo ed pomocou prveho prejdem neaky subor tak mi hodi normalne datum poslednej zmeny, lenze ked to prechadzam pomocou druheho programu tak to furt na kazdy subor hadze Cannot display the time
_________________ Lenovo IdeaPad G580 *Intel Core i3-2310M 2.10GHz * 4GB RAM * Nvidia GeForce 610M 1GB * 500GB HDD SATA * Windows 10 64-bit || Ubuntu 14.04 |
|
Registrovaný: 07.04.12 Prihlásený: 02.06.21 Príspevky: 907 Témy: 54 | Napísal ado130: 09.10.2013 22:43 | |
|
Áno máš pravdu, ono je chyba v tom, ako máš tento riadok Kód: if (!stat(entry->d_name, &b)) { Tam(entry->d_name) treba zadať konkrétnu cestu k súboru(napr. C:\\Hello.txt) a ja tam zadávam len názov súboru(Hello.txt) no a teraz nejak neviem ako to spraviť, keby sa našiel náhodou niekto iný. Edit:OK, myslím, že už to funguje: Kód: #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <string.h> #include <errno.h> #include <time.h> #include <conio.h> #include <sys/stat.h>
void cas() { time_t rawtime; struct tm *timeinfo; char buffer[80];
time( &rawtime ); timeinfo = localtime( &rawtime );
strftime ( buffer, 80, "Time: %d/%m/%Y %H:%M:%S", timeinfo ); printf( "%s\n", buffer ); }
int main () { DIR * d; char * dir_name = "C:\\"; char t[ 100 ] = ""; struct stat b; char files[200];
/* Open the current directory. */
d = opendir (dir_name);
if (! d) { fprintf (stderr, "Cannot open directory '%s': %s\n", dir_name, strerror (errno)); exit (EXIT_FAILURE); } while (1) { struct dirent * entry; entry = readdir (d); if (! entry) { break; } printf("_________________________________________________ \n"); printf("%s\n", entry->d_name); strcpy (files,dir_name); strcat (files,"//"); strcat (files,entry->d_name); //char file[] = "entry->d_name"; if (!stat(files, &b)) { strftime(t, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime)); printf("\nLast modified date and time = %s\n", t); } else { printf("Cannot display the time.\n"); } cas(); printf("------------------------------------------------- \n"); printf("\n"); printf("\n"); } /* Close the directory. */ if (closedir (d)) { fprintf (stderr, "Could not close '%s': %s\n", dir_name, strerror (errno)); exit (EXIT_FAILURE); } getch(); return 0; }
_________________ Notebook: Dell Inspiron 15-7537= i5-4200U|nVidia GT 750M 2GB|RAM 6GB|250GB Samsung 850 EVO|W8.1|Cooler Master NotePal U3 Pc: Asus Rog Strix B360-G | i7-8700 | MSI 1080 Gaming X | Crucial Ballistix 16GB 2666MHz Dual Ranked | Samsung 970 Evo | Crucial MX500 | WD Red | Fera 3 | Arctic F12 Silent | Seasonic Focus Plus 650W Gold | Fractal Design Mini C TG Disk: Western Digital Elements 1TB USB 2.0; Seagate Expansion 2TB USB 3.0 Príslušenstvo: A4tech Bloody V3 V-Track Core 3 + A4tech Bloody B-070; A4tech Bloody B120; A4tech Bloody G501; ATH-M40x; MSI Clutch M40 Monitor: Dell U2515H Mobil: Xiaomi Redmi Note 3 Special Edition |
|
| Stránka: 1 z 1
| [ Príspevkov: 6 ] | |
| Nemôžete zakladať nové témy v tomto fóre Nemôžete odpovedať na témy v tomto fóre Nemôžete upravovať svoje príspevky v tomto fóre Nemôžete mazať svoje príspevky v tomto fóre
|
|