fork download
  1. #include <dirent.h> //czytamy pliki i foldery
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <ctime>
  5. #include <string>
  6. #include <sys/stat.h> //status pliku
  7. using namespace std;
  8.  
  9. string convertTime (time_t takeTime)
  10. {
  11. struct tm *timeConverter = localtime(&takeTime);
  12. return(asctime(timeConverter));
  13. }
  14.  
  15. int main()
  16. {
  17. DIR *dir;
  18. struct dirent *dp;
  19. struct stat statbuf;
  20. string strFile;
  21.  
  22. dir = opendir("/home/piotr/Dokumenty/C/Nauka programy");
  23.  
  24. while ((dp = readdir(dir))!=NULL) //czytaj w folderze az przejdziesz przez wszystkie pliki
  25. {
  26. strFile=dp->d_name; //read file name
  27.  
  28. if ((strFile.at(strFile.size()-1)!='~')&&(strFile!=".")&&(strFile!="..")) //nie widzi dzieki temu usunietych programow (tablica ma tylde na koncu ze wyjebane / usuniete)
  29. { // kropki to tylko odniesienia do polozenia
  30. stat(dp->d_name,&statbuf); //jak rowne -1 to poprawny (mozna coutowac)
  31. cout<<endl<<"file name: "<<strFile<<endl; //nazwa pliku
  32. cout<<"device ID of device containing: "<<statbuf.st_dev<<endl; //ID partycji
  33. cout<<"file serial number: "<<statbuf.st_ino<<endl; //ID tablicy pamięci
  34.  
  35. cout<<"mode of file: "<<statbuf.st_mode<<endl; //zbior cech pliku
  36. //interesuje nas co z tego numery wyrwiemy
  37.  
  38. // jaki konkretny typ "pliku" to jest
  39. cout<<boolalpha<<"is it regular file: "<<(S_ISREG(statbuf.st_mode))<<endl; //badamy czy to zwykly plik dwie metody sa na badania
  40. //cout<<"is it regular file: "<<((statbuf.st_mode & S_IFMT) == S_IFREG)<<endl; zakomentowana bo raz wystarczy ;>
  41.  
  42. //specjalny typ pliku:
  43. cout<<"is it directory: "<<(S_ISDIR(statbuf.st_mode))<<endl; //czy to scierzka
  44. cout<<"is it character device: "<<(S_ISCHR(statbuf.st_mode))<<endl; //driver - wysyla i otrzymuje po jednym znaku serial ports, pararell ports, sound card
  45. cout<<"is it block device: "<<(S_ISBLK(statbuf.st_mode))<<endl; //driver - wysyla cale bloki informcji, hard disc , usb camera ,disc on key;
  46. cout<<"is it FIFO named pipe: "<<(S_ISFIFO(statbuf.st_mode))<<endl; //komunikacja miedzy programami (lokalnymi) wysyla informacje z jednego procesu do drugiego
  47. cout<<"is it socket: "<<(S_ISSOCK(statbuf.st_mode))<<endl; //komunikacja miedzy programami (lokalnymi) -specyficzny
  48. cout<<"is it symbolic link: "<<(S_ISLNK(statbuf.st_mode))<<endl; //wskazuje jakas scierzke programowi gdzie ma szukac innego programu
  49. cout<<noboolalpha;// jest jeszcze typ pliku door ale tylko na jednym pewnym systemie - olac
  50. //moze nie rozpoznać typu pliku co wtedy???
  51.  
  52. cout<<"number of hard links to file: "<<statbuf.st_nlink<<endl; //odniesienia do jakiegos miejsca (ze plik wymaga czegos np w swoim folderze a to jest gdzies indziej) sa miekkie i twarde linki - zaleza od uprawnien
  53. cout<<"user ID of file: "<<statbuf.st_uid<<endl;
  54. cout<<"grup ID of file: "<<statbuf.st_gid<<endl;
  55. cout<<"device ID: "<<statbuf.st_rdev<<endl; //rozszerzona inf ID partycji
  56. cout<<"file size: "<<statbuf.st_size<<endl; //wielkosc pliku
  57. cout<<"block size for I/O: "<<statbuf.st_blksize<<endl; //minimalna wielkosc jaka zajmie plik na dysku
  58. cout<<"number of blocks allocated for this number: "<<statbuf.st_blocks<<endl; //liczba blokow dla pliku
  59. cout<<"time of last acces: "<<convertTime(statbuf.st_atime); //czas ostatniego wejscia w plik
  60. cout<<"time of last file modification: "<<convertTime(statbuf.st_mtime); //czas ostatniej zmiany pliku
  61. cout<<"time of last file status change: "<<convertTime(statbuf.st_ctime); //czas ostatniego wejscia w plik
  62.  
  63. }
  64. }
  65. }
Runtime error #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Standard output is empty