Thread: FileBrowser (Directory Listing) Needs some help...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    45

    FileBrowser (Directory Listing) Needs some help...

    Ive been looking into a Basic 'Debug' Text Filebrowser just for informational purposes on structures and how to point to a value in one (->) and so Im making a simple filebrowser in the DOS printf debug statements...

    So far I can:
    ~Get how many files are in a folder
    ~List them with file numbers
    ~Read files line-by-line and print them to screen

    Code:
               Directory ->          C:/cygwin/home/owner/resources
               Files in Directory:
    0->.
    1->..
    2->cheatbook.c
    3->DRAGON1.CPP
    4->Filelist.c
    5->filing.exe
    6->flib.c
    7->flib.h
    8->line.c
    9->line.exe
    10->mp3player.c
    11->mp3player.h
    12->puttytel.exe
    13->replace.c
    Thats what is printed out when in my working directory,

    I need to know where i can go to learn more (or maybe you guyz post an example? but I heard you cant help me via direct code) about how to 'cd' into directories and such...

    Another thing is I want to know how to 'select' things on the browser. Like have 'up' move a highlightening color of the text up 1 in the list, that way I can read the file's easy...

    If you want to see my code, ill post it here, maybe someone could tell me if it is suffienct enough?

    P.S. This viewing function has worked for me before perfectly, but now it isnt... Could someone tell me whats wrong?
    Code:
    void FileRead(char* FilePath) {
         FILE *fp;
         fp = fopen(FilePath, "r");
         char line[MAXLINE];
         int count = 0;
         printf("Now Opening: %s\n", FilePath);
         while ( fgets(line, sizeof line, fp) != NULL)
         {
               printf("%2d | %s\n", ++count, fp);
         }
    }
    It prints like 13 lines with 3 characters of binary or soemthing, and when i put a '*' infront of the 'fp' in the while loop, i get the file's stuff, but like a billion times... the ratio is for every '1' line (the number is placed next to the line), it prints out 15 lines of actual code, and there all jumbled around too...

    Anyhelp would be great

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by SG57
    I need to know where i can go to learn more (or maybe you guyz post an example? but I heard you cant help me via direct code) about how to 'cd' into directories and such...
    Did you peek at the FAQ?

    Quote Originally Posted by SG57
    It prints like 13 lines with 3 characters of binary or soemthing, and when i put a '*' infront of the 'fp' in the while loop, i get the file's stuff, but like a billion times...
    Random syntax won't help, try to understand what you are coding.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    45
    Well, the asteriks means a pointer to the buffer array... Correct?

    EDIT

    I have looked at the FAQ and its no good towards me (for the directory listing) and for the file reading/displaying, I have figured out that that it prints out:
    Code:
    Now Opening
    Line 2: line 2
    line 3
    4
    5
    6
    7
    8
    9
    10
    
    Line 3: line 3
    5
    6
    7
    8
    9
    10
    
    Line 4: 4
    5
    6
    7
    8
    9
    10
    
    Line 5: 5
    6
    7
    8
    9
    10
    
    Line 6: 6
    7
    8
    9
    10
    
    Line 7: 7
    8
    9
    10
    
    Line 8: 8
    9
    10
    
    Line 9: 9
    10
    
    Line 10: 10
    
    Line 10:
    I can see what its doing, but im not sure how to prevent it from printing the ENTIRE file when I had stated it to 'gets()' AKA get 1 string/line until \0 or \n, so I cant see the problem...
    Last edited by SG57; 06-04-2006 at 03:38 AM.

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    45
    Ok, nevermind about the File thing, i got it working :-) now on about the File Browsing?

    I can list the items in a folder, just not get a cursor/selector for the files worikng, it involves about 3 for loops i know, but I cant seem to get it working or where to start really...

    Does anyone know of any where i can go that has a basic example of directory browsing or something Directory? Not the FAQ or google, ive searched booth...

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Google "dirent", "sys/stat.h", "c directory handling" etc.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. On reading Directory contents and listing them.
    By Deathfrost in forum C Programming
    Replies: 9
    Last Post: 07-14-2009, 08:21 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Listing specific files in a directory
    By knirirr in forum C Programming
    Replies: 14
    Last Post: 01-29-2008, 05:42 AM
  4. recursive directory listing help
    By laney69er in forum C Programming
    Replies: 2
    Last Post: 03-13-2006, 01:07 PM
  5. Directory listing
    By brif in forum C++ Programming
    Replies: 1
    Last Post: 10-10-2002, 06:44 AM