-
The problem statement, all variables and given/known data:
I'm trying to use a directory path to enter a new directory and sort the files there. I'm using the language C with a system call in Unix to sort the files from smallest to largest. -
Relevant commands, code, scripts, algorithms:
system("ls -al | sort -k5n >> tempfile.txt");
This command enters the sorted data into a temporary directory named tempfile.txt. Tempfile.txt is later deleted. But the command:
system("ls -al | sort -k5n");
sorts only the data in the current directory. I would like to be able to sort data in any directory entered into my program.
- The attempts at a solution (include all code and scripts):
i've tried:
sprintf(cmd, "cd %s", argv[PATH]);
system(cmd);
to change directories before using the sort command. But this doesn't work. I do not know very much about the Unix language to create a command that changes directories and sorts the files it finds there.
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University at Albany, Albany NY, United States, S.S. Ravi, CSI 402
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).