-
Notifications
You must be signed in to change notification settings - Fork 3
/
getsnames.c
51 lines (38 loc) · 1.11 KB
/
getsnames.c
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
47
48
49
50
51
#include <stdio.h>
#include <dirent.h>
#include<stdlib.h>
int main(void)
{
struct dirent *de; // Pointer for directory entry
// opendir() returns a pointer of DIR type.
DIR *dr = opendir(".");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return 0;
}
// Refer http://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html
// for readdir()
while ((de = readdir(dr)) != NULL)
printf("%s\n", de->d_name);
printf("\n ------- NOW WE WILL MOVE THE FILES ---------- \n");
char str[50]="cp *.c /home/shivam/Desktop/Rahul3";
//scanf("%[^\n]%*c", str);
//str=
//printf("%s", str);
system(str);
if(system(str)){
printf("\n Files copied \n");
}
else
printf("\n Files copied \n");
char arr[1000]="ls";
system(arr);
// to read the array
int i;
for(i=0;i<1000;i++){
printf("%s",arr);
}
closedir(dr);
return 0;
}