-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetOrderNum.c
More file actions
46 lines (43 loc) · 1 KB
/
GetOrderNum.c
File metadata and controls
46 lines (43 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <dirent.h>
#define PATH "/home/braude/Black_Friday/"
#define BUFF 128
#define ORDER "_Order"
int main(int argc, char* argv[]){
int fileCount=0;
char *path;
DIR * dirp;
struct dirent * entry;
if(argc != 2){
printf("This command gets only one parameter - company's name\n");
exit(-1);
}
if((path = (char*)malloc(sizeof(char) * BUFF)) == NULL){
printf("Allocation failure\n");
exit(-1);
}
strcpy(path, PATH);
strcat(path, argv[1]);
strcat(path, ORDER);
dirp = opendir(path);
if(dirp == NULL)
{
free(path);
printf("Company Not Found!\n");
exit(-1);
}
while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_UNKNOWN) { //this linux image doenst get anything but this type for files.
fileCount++;
}
}
closedir(dirp);
printf("%s ---- %d orders\n",argv[1], fileCount);
free(path);
return 0;
}