Results 1 to 6 of 6
Hello everyone,
is anyone know a file-browser (template, code, ...) witch I can implement into my c-program (command-line only)
functions I need:
1. browsing directory's
2. list files
3. pick ...
- 09-23-2011 #1
commandline filebrowser for c program
Hello everyone,
is anyone know a file-browser (template, code, ...) witch I can implement into my c-program (command-line only)
functions I need:
1. browsing directory's
2. list files
3. pick a file and get the path back
program is written in c for Linux 2.6
Thx
- 09-23-2011 #2
- 09-23-2011 #3
Thx for the answer.
I think you understand me wrong.
I was looking for code witch allows me to browse through the directory of my hard disk during the runtime of my program.
hope it is clear now and sorry for my English . . .
- 09-24-2011 #4Just Joined!
- Join Date
- Jan 2010
- Posts
- 27
Do you know of Midnight Commander (mc) ?
It is a very advanced directory browser for text console:
http://www.thegeekstuff.com/wp-conte...ull-screen.jpg
Console HT Editor also has some nice directory browser, but it uses some UI style in the vein of TurboVision:
HT editor | Download HT editor software for free at SourceForge.net
so browser code probably is quite abstract and complex.
Then Nano editor uses directory browsing also:
http://tuxradar.com/files/LXF131.nano.list.jpg
There is also recovery tool TestDisk for text console, which implements some file browser too:
http://screenshots.en.softonic.com/e...estdisk-27.jpg
Note that all these products are licensed as GPL:)
- 09-24-2011 #5Just Joined!
- Join Date
- Feb 2009
- Posts
- 6
check this code,
and for more information about this code , please read "Beginning Linux Programming 4th edition", chapter 3: Working with Files#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
void printdir( char *dir, int depth)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;
char buf[24];
if((dp = opendir(dir)) == NULL) {
fprintf(stderr, "cannot open dirctory: %s\n", dir);
return;
}
// getcwd(buf, 64);
// printf("getcwd: %s\n", buf);
// printf("dir: %s\n", dir);
chdir(dir);
// getcwd(buf, 64);
// printf("getcwd: %s\n", buf);
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode)) {
if(strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
continue;
printf("%*s%s\n", depth,"", entry->d_name);
/* Recurse at a new indent level */
printdir(entry->d_name, depth+4);
}
else
printf ( "%*s%s\n", depth,"", entry->d_name );
}
chdir("..");
closedir(dp);
}
int main()
{
printf("Diectory scan of /home:\n");
printdir("/home", 0);
exit(0);
}
Hope this will help you.
- 09-24-2011 #6
Thx for the answers. I was expecting that there is a framework I simple can implement into my software.
The functionality from testdisk would be great. But extracting code from an other project is complex like writing it by my own.
Thx again for trying to help, I think I start with the code above and writing it by my self.


Reply With Quote